#!/bin/bash # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi source /a/bin/bash-bear-trap/bash-bear shopt -s nullglob shopt -s dotglob # temp disabled: x2wg kwwg # this list duplicated in brc2 ralerts for h in bk je li x3wg kdwg sywg; 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 -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}')") case $h in frodo) hours=200 ;; *) hours=20 ;; esac if (( logsec < EPOCHSECONDS - 60*60*hours )); then echo $0: host $h ssh /usr/local/bin/check-mailq fail for over $hours hours fi fi printf "%s\n" "$c" | ts "%F %T" >> $statefile fi done