# limitations under the License.
case $1 in
- -h|--help)
- cat <<'EOF'
-usage: logmail CMD [ARGS...]
+ -h|--help)
+ cat <<'EOF'
+usage: failmail CMD [ARGS...]
Send mail in case of failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
EOF
- exit 0
- ;;
+ exit 0
+ ;;
esac
+mailto=$USER@localhost
+if [[ $MAILTO ]]; then
+ mailto=$MAILTO
+fi
+
t=$(mktemp)
if ! "$@" &>"$t"; then
- mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
- rm "$t"
+ mail -s "$HOSTNAME: $*" $mailto <"$t"
+ rm "$t"
fi
exit 0