more mail fixes
[distro-setup] / filesystem / usr / local / bin / mailtest-check
1 #!/bin/bash
2 set -eE -o pipefail
3 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
4
5 if [[ $EUID != 1000 ]]; then
6 echo "$0: error run as normal user" >&2
7 exit 1
8 fi
9
10 cd /m/md/l/testignore/new
11 shopt -s nullglob
12
13 # we run this cronjob along with sending the test email every 10
14 # minutes, so give it 2 minutes to arrive, then if there is an email at
15 # least 23 minutes old, the last 2 test emails have failed.
16 if [[ ! $@ && $- != *i* ]]; then
17 sleep 120
18 fi
19
20 last_sec=0
21 for file in *; do
22 if [[ $file -nt $latest ]]; then
23 latest=$file
24 fi
25 done
26
27 if [[ $latest ]]; then
28 last_sec=$(awk '/^Subject: / {print $3}' $latest)
29 fi
30
31 now=$(date +%s)
32 limit=$(( now - 60 * 23 ))
33
34 if (( last_sec <= limit )); then
35 echo $HOSTNAME mailtest failure
36 touch /nocow/user/mailtest-failure
37 else
38 rm -f /nocow/user/mailtest-failure
39 fi
40
41 find -type f -mtime +1 -delete