#!/bin/bash set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR if [[ $EUID != 1000 ]]; then echo "$0: error run as normal user" >&2 exit 1 fi shopt -s nullglob # 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 if [[ ! $1 && $- != *i* ]]; then sleep 60 fi folders=(/m/md/l/testignore{,2}/new) find ${folders[@]} -type f -mtime +1 -delete for folder in ${folders[@]}; do cd $folder last_sec=0 for file in *; do if [[ $file -nt $latest ]]; then latest=$file fi done if [[ $latest ]]; then last_sec=$(awk '/^Subject: / {print $3}' $latest) fi now=$(date +%s) limit=$(( now - 60 * min_limit )) if (( last_sec <= limit )); then echo $HOSTNAME mailtest failure touch /nocow/user/mailtest-failure break else rm -f /nocow/user/mailtest-failure fi done