- journalctl -u $service.service --after-cursor=$(<$file) | \
- mail -s "$HOSTNAME: $service failure" $u@localhost
+ send_mail=true
+ fi
+ fi
+ if $send_mail; then
+ echo "sysd-mail-once: emailing on $errors errors. exit code: $code"
+ mi exim -odf -t <<EOF
+To: $to
+From: $(id -u -n)@$(hostname -f)
+Subject: $HOSTNAME: $service exit code: $code
+
+$(journalctl -u $service.service --after-cursor="$(<$file)")
+EOF
+ fi
+else
+ if [[ $file ]]; then
+ m rm -f $file
+ if [[ $file == $c$errors ]]; then
+ echo "sysd-mail-once: emailing success after >= $errors errors."
+ mi exim -odf -t <<EOF
+To: $to
+From: $(id -u -n)@$(hostname -f)
+Subject: $HOSTNAME: $service success
+
+EOF