-else # $@ failed
- if [[ $file ]]; then
- i=${file#$c}
- if (( i < errors )); then
- new_file=$c$((i+1))
- mv $file $new_file
- file=$new_file
- if [[ $file == $c$errors ]]; then
- journalctl -u $service.service --after-cursor=$(<$file) | \
- mail -s "$HOSTNAME: $service failure" $u@localhost
- fi
- fi
- else
- file=${c}1
- printf "%s\n" "$cursor" >$file
+ fi
+ if $send_mail; then
+ 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
+ exim -odf -t <<EOF
+To: $to
+From: $USER@$(hostname -f)
+Subject: $HOSTNAME: $service success
+
+EOF