X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=sysd-mail-once;h=2f7f4d5d9efd035d7803d623bb946090f4597be7;hb=559cd04634ae77a27b830c811c38f240993c1775;hp=a7840aad763463c93d5cb960b7c94092c00015f7;hpb=5a8c5e87d9c5b9c966b2145a9f12ec15220ccd00;p=log-quiet diff --git a/sysd-mail-once b/sysd-mail-once index a7840aa..2f7f4d5 100755 --- a/sysd-mail-once +++ b/sysd-mail-once @@ -18,11 +18,12 @@ set -eE -o pipefail trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR errors=3 -cbase=/var/local/cron-errors +cbase=$HOME/sysd-mail-once-state +to=root case "$1" in - -h|--help) - cat <$file + if (( errors == 1 )); then + send_mail=true fi + fi + if $send_mail; then + journalctl -u $service.service --after-cursor=$(<$file) | \ + mail -s "$HOSTNAME: $service exit code: $code" "$to" + fi else - 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 + if [[ $file ]]; then + rm -f $file + if [[ $file == $c$errors ]]; then + echo | mail -s "$HOSTNAME: $service success" "$to" fi + fi fi