add verbose option, license for small program
[log-quiet] / failmail
index 377564e294b6d5a038b1bec39352f84de32ace15..c420465829dafb1e1873ebc6445ca9a596a7a2be 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"
+code=0
+"$@" &>"$t" || code=$?
+if (( code )); then
+  mail -s "$HOSTNAME: code: $code cmd: $*" $mailto <"$t"
   rm "$t"
 fi
 exit 0