3 export SGMONDIR="$(dirname "$(realpath -- "$0")")"
5 [ -z "$1" ] && SGMONSRV="$(basename "$PWD")" || SGMONSRV="$1"
7 export SGMONTMP=`mktemp -d -t sgmon`
10 trap "rm -fr state $SGMONTMP" HUP PIPE INT QUIT TERM EXIT
13 [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=1
14 [ -s state/attempts ] && read attempts < state/attempts || attempts=0
15 [ -x run ] && cmd=./run || cmd="sh -e run"
16 if $cmd >state/stdout 2>state/stderr ; then
17 if [ "$attempts" -ge "$max_attempts" ] ; then
18 "$SGMONDIR"/notify-ok.sh
25 attempts=$(( $attempts + 1 ))
26 echo $attempts > state/attempts
27 echo BAD ${attempts}/${max_attempts}
28 if [ $attempts -eq $max_attempts ] ; then
29 "$SGMONDIR"/notify-bad.sh
32 [ -s period ] && read period < period || period=$PERIOD_DEFAULT