more thorough mail testing
authorIan Kelling <ian@iankelling.org>
Mon, 9 Nov 2020 03:32:07 +0000 (22:32 -0500)
committerIan Kelling <ian@iankelling.org>
Mon, 9 Nov 2020 03:32:07 +0000 (22:32 -0500)
mailtest-check

index 2ab174e720cdc68430dc492490c7feb690f01b1b..59b7dce86641cf02b55cee5ecc7fadcc54e8ac8e 100755 (executable)
@@ -9,44 +9,52 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?. PIPESTATUS: ${PIPES
 
 shopt -s nullglob
 
+e() { $int || return 0; printf "mailtest-check: %s\n" "$*"; }
+
+
 # We run this cronjob along with sending the test email every 5 minutes,
 # so give it 1 minute to arrive, then if the latest email is older than
 # 7 minutes, the last 2 haven't arrived in a reasonable amount of time.
 min_limit=7
 
+int=true
 if [[ ! $1 && $- != *i* ]]; then
+  int=false
   sleep 60
 fi
 
 
-folder=/m/md/l/testignore
+folders=(/m/md/l/testignore{,zroe})
 case $HOSTNAME in
   bk)
-    folder=/m/md/expertpathologyreview.com/testignore
+    folders=(/m/md/{expertpathologyreview.com,amnimal.ninja}/testignore)
     ;;
   je)
-    folder=/m/md/je.b8.nz/testignore
+    folders=(/m/md/je.b8.nz/testignore)
     ;;
 esac
-find $folder/new $folder/cur -type f -mmin +300 -delete
-
 
-cd $folder
-last_sec=0
-# webmail sends them to cur it seems
-for file in new/* cur/*; do
-  if [[ $file -nt $latest ]]; then
-    latest=$file
+for folder in ${folders[@]}; do
+
+  find $folder/new $folder/cur -type f -mmin +300 -delete
+  cd $folder
+  last_sec=0
+  # webmail sends them to cur it seems
+  for file in new/* cur/*; do
+    if [[ $file -nt $latest ]]; then
+      latest=$file
+    fi
+  done
+
+  if [[ $latest ]]; then
+    e latest = $folder/$latest
+    last_sec=$(awk '/^Subject: / {print $4}' $latest)
   fi
-done
 
-if [[ $latest ]]; then
-  last_sec=$(awk '/^Subject: / {print $4}' $latest)
-fi
+  now=$(date +%s)
+  limit=$(( now - 60 * min_limit ))
 
-now=$(date +%s)
-limit=$(( now - 60 * min_limit ))
-
-if (( last_sec <= limit )); then
-  echo $HOSTNAME mailtest failure $(date -d @$last_sec +'%a %m-%d %H:%M')
-fi
+  if (( last_sec <= limit )); then
+    echo $HOSTNAME mailtest $folder $(date -d @$last_sec +'%a %m-%d %H:%M')
+  fi
+done