fix vpn host naming
[distro-setup] / 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 shopt -s nullglob
11
12
13 # We run this cronjob along with sending the test email every 5 minutes,
14 # so give it 1 minute to arrive, then if the latest email is older than
15 # 7 minutes, the last 2 haven't arrived in a reasonable amount of time.
16 min_limit=7
17
18 if [[ ! $1 && $- != *i* ]]; then
19 sleep 60
20 fi
21
22
23 folder=/m/md/l/testignore/new
24 find $folder -type f -mtime +1 -delete
25
26
27 cd $folder
28 last_sec=0
29 for file in *; do
30 if [[ $file -nt $latest ]]; then
31 latest=$file
32 fi
33 done
34
35 if [[ $latest ]]; then
36 last_sec=$(awk '/^Subject: / {print $3}' $latest)
37 fi
38
39 now=$(date +%s)
40 limit=$(( now - 60 * min_limit ))
41
42 if (( last_sec <= limit )); then
43 echo $HOSTNAME mailtest failure
44 touch /nocow/user/mailtest-failure
45 break
46 else
47 rm -f /nocow/user/mailtest-failure
48 fi