From 75264bc16a77ee1ebfcb9859e649c3cf0dc2fee5 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 24 Mar 2003 02:21:02 +0000 Subject: Sends email if non-zero return code from command git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@455 f882894a-f735-0410-b71e-b25c423dba1c --- tools/mail_error | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 tools/mail_error (limited to 'tools/mail_error') diff --git a/tools/mail_error b/tools/mail_error new file mode 100755 index 00000000..4349c21d --- /dev/null +++ b/tools/mail_error @@ -0,0 +1,22 @@ +#!/bin/bash +# mail_error -o file -m email_address command +# Runs command and redirects all output to file +# If command rc != 0, sends file to email_address + +function die { echo $1 ; exit 1; } + +while getopts "o:m:" c; do + case $c in + o) output_file=$OPTARG;; + m) email=$OPTARG;; + \*) echo "oops";; + esac +done +shift $(($OPTIND-1)) +echo "output_file=$output_file email=$email" + +[[ -z $1 ]] && die "Must specify command" + +if ! "$@" > $output_file 2>&1 ; then + mail -s "mail_error fail: $@" $email < $output_file +fi -- cgit v1.2.3-74-g34f1