bunch of fixes, change sy host, deploy some new stuff
[distro-setup] / check-remote-mailqs
1 #!/bin/bash
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4
5 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
6
7 source /a/bin/errhandle/err
8
9 shopt -s nullglob
10 shopt -s dotglob
11
12 for h in bk je li frodo kwwg x3wg x2wg kdwg; do
13 statedir=/b/bash_unpublished/mailq-state
14 statefile=$statedir/$h
15 [[ -d $statedir ]] || continue
16 if [[ $HOSTNAME == "${h%wg}" ]]; then
17 rm -f $statefile
18 continue
19 fi
20 if c=$(timeout -v 10 ssh root@$h.b8.nz /usr/local/bin/check-mailq 2>&1 ); then
21 rm -f $statefile
22 if [[ $c ]]; then
23 echo q:$h=$c
24 fi
25 else
26 if [[ -s $statefile ]]; then
27 logsec=$(date +%s -d "$(head -n1 $statefile | awk '{print $1,$2}')")
28 nowsec=$(date +%s)
29 if (( logsec < nowsec - 60*60*48 )); then
30 echo $0: host $h ssh /usr/local/bin/check-mailq fail for over 48 hours
31 fi
32 fi
33 printf "%s\n" "$c" | ts "%F %T" >> $statefile
34 fi
35 done