X-Git-Url: https://iankelling.org/git/?p=log-quiet;a=blobdiff_plain;f=sysd-mail-once;fp=sysd-mail-once;h=711479c84b1dbecdeefbfa76b64122eaeb09467a;hp=e53d6ee6e5f41df4df6b78a702e5f3f3ae9e05e9;hb=84cffb3bd9ae61b32f9922bfb5ab038834048a8e;hpb=0025a0904ad317a102b2e94262a4b01942f13d52 diff --git a/sysd-mail-once b/sysd-mail-once index e53d6ee..711479c 100755 --- a/sysd-mail-once +++ b/sysd-mail-once @@ -54,14 +54,11 @@ u=${USER:-root} if [[ ! $file ]]; then cursor=$(journalctl --show-cursor -qn0|sed 's/^\s*--\scursor:\s*//') fi -if "$@"; then - if [[ $file ]]; then - rm -f $file - if [[ $file == $c$errors ]]; then - echo | mail -s "$HOSTNAME: $service success" $u@localhost - fi - fi -else # $@ failed + +code=0 +"$@" || code=$? +if (( code )); then + send_mail=false if [[ $file ]]; then i=${file#$c} if (( i < errors )); then @@ -69,16 +66,25 @@ else # $@ failed 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 + send_mail=true fi fi else file=${c}1 printf "%s\n" "$cursor" >$file if (( errors == 1 )); then - journalctl -u $service.service --after-cursor=$(<$file) | \ - mail -s "$HOSTNAME: $service failure" $u@localhost + send_mail=true + fi + fi + if $send_mail; then + journalctl -u $service.service --after-cursor=$(<$file) | \ + mail -s "$HOSTNAME: $service exit code: $code" $u@localhost + fi +else + if [[ $file ]]; then + rm -f $file + if [[ $file == $c$errors ]]; then + echo | mail -s "$HOSTNAME: $service success" $u@localhost fi fi fi