bunch of fixes, change sy host, deploy some new stuff
[distro-setup] / check-remote-mailqs
index 8a2fc85461ef806b7a738004ad9554718c71c418..b47810162fa14f7d26aff69d294c0ae17576f953 100755 (executable)
@@ -9,12 +9,27 @@ source /a/bin/errhandle/err
 shopt -s nullglob
 shopt -s dotglob
 
-
-for h in bk.b8.nz je.b8.nz tp.b8.nz vpn1 x2 x3.b8.nz frodo.b8.nz kd.b8.nz kw iankelling.org bk.b8.nz; do
-  if [[ $HOSTNAME == "${h%%.*}" ]]; then
+for h in bk je li frodo kwwg x3wg x2wg kdwg; do
+  statedir=/b/bash_unpublished/mailq-state
+  statefile=$statedir/$h
+  [[ -d $statedir ]] || continue
+  if [[ $HOSTNAME == "${h%wg}" ]]; then
+    rm -f $statefile
     continue
   fi
-  if c=$(timeout 1 ssh root@$h /b/ds/check-mailq 2>/dev/null ) && [[ $c ]]; then
-    echo q:$h=$c
+  if c=$(timeout -v 10 ssh root@$h.b8.nz /usr/local/bin/check-mailq 2>&1 ); then
+    rm -f $statefile
+    if [[ $c ]]; then
+      echo q:$h=$c
+    fi
+  else
+    if [[ -s $statefile ]]; then
+      logsec=$(date +%s -d "$(head -n1 $statefile | awk '{print $1,$2}')")
+      nowsec=$(date +%s)
+      if (( logsec < nowsec - 60*60*48 )); then
+        echo $0: host $h ssh /usr/local/bin/check-mailq fail for over 48 hours
+      fi
+    fi
+    printf "%s\n" "$c" | ts "%F %T" >> $statefile
   fi
 done