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"
+code=0
+"$@" &>"$t" || code=$?
+if (( code )) || [[ -s $t ]]; then
+ mail -s "$HOSTNAME: code: $code cmd: $*" $mailto <"$t"
rm "$t"
fi
exit 0