add mail to option for systemd
[log-quiet] / sysd-mail-once
index 4ccc81c3f37ba1a4ae2554818c2b7f7075de1895..2f7f4d5d9efd035d7803d623bb946090f4597be7 100755 (executable)
@@ -19,10 +19,11 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 errors=3
 cbase=$HOME/sysd-mail-once-state
+to=root
 case "$1" in
   -h|--help)
     cat <<EOF
-Usage: sysd-log-once [-ERRORS] SERVICE COMMAND [ARGS...]
+Usage: sysd-mail-once [-t TO_ADDRESS] [-ERRORS] SERVICE COMMAND [ARGS...]
 For systemd timers, email on repeated failure & success after failure.
 
 In the service triggered by the timer, prepend this script to the ExecStart.
@@ -40,6 +41,10 @@ EOF
     errors=${1#-}
     shift
     ;;
+  -t)
+    to="$2"
+    shift 2
+    ;;
 esac
 service=$1
 shift
@@ -77,13 +82,13 @@ if (( code )); then
   fi
   if $send_mail; then
     journalctl -u $service.service --after-cursor=$(<$file) | \
-      mail -s "$HOSTNAME: $service exit code: $code" root
+      mail -s "$HOSTNAME: $service exit code: $code" "$to"
   fi
 else
   if [[ $file ]]; then
     rm -f $file
     if [[ $file == $c$errors ]]; then
-      echo | mail -s "$HOSTNAME: $service success" root
+      echo | mail -s "$HOSTNAME: $service success" "$to"
     fi
   fi
 fi