errors=3
cbase=$HOME/sysd-mail-once-state
+to=root
case "$1" in
-h|--help)
cat <<EOF
-Usage: sysd-log-once [-ERRORS] SERVICE COMMAND [ARGS...]
+Usage: sysd-mail-once [-t TO_ADDRESS] [-ERRORS] SERVICE COMMAND [ARGS...]
For systemd timers, email on repeated failure & success after failure.
In the service triggered by the timer, prepend this script to the ExecStart.
errors=${1#-}
shift
;;
+ -t)
+ to="$2"
+ shift 2
+ ;;
esac
service=$1
shift
fi
if $send_mail; then
journalctl -u $service.service --after-cursor=$(<$file) | \
- mail -s "$HOSTNAME: $service exit code: $code" root
+ mail -s "$HOSTNAME: $service exit code: $code" "$to"
fi
else
if [[ $file ]]; then
rm -f $file
if [[ $file == $c$errors ]]; then
- echo | mail -s "$HOSTNAME: $service success" root
+ echo | mail -s "$HOSTNAME: $service success" "$to"
fi
fi
fi