X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=logmail;h=bece0ae8683ecd72818599f9a42dcb5d6e312200;hb=8833ce1c9db6bf21c029bb982ccd5c3295fa41b8;hp=cac1e21372cb80389189987d2910279e125b235e;hpb=caf623ada289608bdbcc2216058057a7390f7939;p=log-quiet diff --git a/logmail b/logmail index cac1e21..bece0ae 100755 --- a/logmail +++ b/logmail @@ -14,18 +14,22 @@ # limitations under the License. case $1 in - -h|--help) - cat <<'EOF' + -h|--help) + cat <<'EOF' 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 - ;; + exit 0 + ;; esac t=$(mktemp) -if ! "$@" &>"$t" || [[ ! -s $t ]]; then - mail -s "$HOSTNAME: $*" $USER@localhost <"$t" - rm "$t" +code=0 +"$@" &>"$t" || code=$? +if (( code )) || [[ -s $t ]]; then + mail -s "$HOSTNAME: code: $code cmd: $*" $mailto <"$t" + rm "$t" fi exit 0