iankelling.org
/
git
/
log-quiet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add script for prometheus logging of systemd service failures
[log-quiet]
/
failmail
diff --git
a/failmail
b/failmail
old mode 100644
(file)
new mode 100755
(executable)
index
703e130
..
c420465
--- a/
failmail
+++ b/
failmail
@@
-14,19
+14,28
@@
# limitations under the License.
case $1 in
# limitations under the License.
case $1 in
-
-h|--help)
-
cat <<'EOF'
-usage:
log
mail CMD [ARGS...]
+ -h|--help)
+ cat <<'EOF'
+usage:
fail
mail CMD [ARGS...]
Send mail in case of failure of CMD
Send mail in case of failure of CMD
+
+Emails to $MAILTO or if unset, $USER@localhost
EOF
EOF
-
exit 0
-
;;
+ exit 0
+ ;;
esac
esac
+mailto=$USER@localhost
+if [[ $MAILTO ]]; then
+ mailto=$MAILTO
+fi
+
t=$(mktemp)
t=$(mktemp)
-if ! "$@" &>"$t"; then
- mail -s "$HOSTNAME: $*" $USER@localhost <"$t"
- rm "$t"
+code=0
+"$@" &>"$t" || code=$?
+if (( code )); then
+ mail -s "$HOSTNAME: code: $code cmd: $*" $mailto <"$t"
+ rm "$t"
fi
exit 0
fi
exit 0