-h|--help)
cat <<EOF
Usage: sysd-mail-once [-t TO_ADDRESS] [-ERRORS] SERVICE COMMAND [ARGS...]
-For systemd timers, email on repeated failure & success after failure.
+For systemd timers, email (with exim) on repeated failure & success after failure.
In the service triggered by the timer, prepend this script to the ExecStart.
The email will contain the service's logs for the last ERRORS runs.
fi
fi
if $send_mail; then
- journalctl -u $service.service --after-cursor=$(<$file) | \
- mail -s "$HOSTNAME: $service exit code: $code" "$to"
+ exim -odf -t <<EOF
+To: $to
+From: $USER@$(hostname -f)
+Subject: $HOSTNAME: $service exit code: $code
+
+$(journalctl -u $service.service --after-cursor=$(<$file))
+EOF
fi
else
if [[ $file ]]; then
rm -f $file
if [[ $file == $c$errors ]]; then
- echo | mail -s "$HOSTNAME: $service success" "$to"
+ exim -odf -t <<EOF
+To: $to
+From: $USER@$(hostname -f)
+Subject: $HOSTNAME: $service success
+
+EOF
fi
fi
fi