fix sysd-mail-once missing email on 1 error, minor improvements
authorIan Kelling <iank@fsf.org>
Mon, 14 Jun 2021 18:11:06 +0000 (14:11 -0400)
committerIan Kelling <iank@fsf.org>
Mon, 14 Jun 2021 18:11:06 +0000 (14:11 -0400)
failmail
logmail
setup
sysd-mail-once

index 377564e294b6d5a038b1bec39352f84de32ace15..6360c7e31c0d84d7d3e2262adc925154683417a1 100755 (executable)
--- a/failmail
+++ b/failmail
 case $1 in
   -h|--help)
     cat <<'EOF'
-usage: logmail CMD [ARGS...]
+usage: failmail CMD [ARGS...]
 
 Send mail in case of failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
 EOF
     exit 0
     ;;
 esac
 
+mailto=$USER@localhost
+if [[ $MAILTO ]]; then
+  mailto=$MAILTO
+fi
+
 t=$(mktemp)
 if ! "$@" &>"$t"; then
-  mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
+  mail -s "$HOSTNAME: $*" $mailto <"$t"
   rm "$t"
 fi
 exit 0
diff --git a/logmail b/logmail
index 4aad395591d9f123072ef545e7d25f5cce937d53..00b6b0a82f6e817a700435f6bd9393c3ae625341 100755 (executable)
--- a/logmail
+++ b/logmail
@@ -19,13 +19,15 @@ case $1 in
 usage: logmail CMD [ARGS...]
 
 Send mail in case of output or failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
 EOF
     exit 0
     ;;
 esac
 t=$(mktemp)
 if ! "$@" &>"$t" || [[ ! -s $t ]]; then
-  mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
+  mail -s "$HOSTNAME: $*" $mailto <"$t"
   rm "$t"
 fi
 exit 0
diff --git a/setup b/setup
index 7ce3624fb7aee0f9be68f6c146897c682f002868..5897f56f69b6906e6545c7196a16c7db1fef7899 100755 (executable)
--- a/setup
+++ b/setup
@@ -65,8 +65,8 @@ if $uninstall; then
   fi
 else
   if $dry; then
-    echo "setup dry run: install -v ${files[*]} /usr/local/bin"
+    echo "setup dry run: install ${files[*]} /usr/local/bin"
   else
-    install -v ${files[@]} /usr/local/bin
+    install ${files[@]} /usr/local/bin
   fi
 fi
index 8feedd377e6324d4d70b5e87f3566495c80fcec9..e53d6ee6e5f41df4df6b78a702e5f3f3ae9e05e9 100755 (executable)
@@ -44,7 +44,7 @@ esac
 service=$1
 shift
 
-c=$cbase/$service
+c=$cbase/$service # c for command file path base
 
 glob="$c[0-9]*"
 arr=($glob); file="${arr[0]}"; [[ $glob != "$file" ]] || file=
@@ -76,5 +76,9 @@ else # $@ failed
   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
+    fi
   fi
 fi