[Nagiosplug-checkins] CVS: nagiosplug/tools mail_error,NONE,1.1
Ton Voon
tonvoon at users.sourceforge.net
Sun Mar 23 18:22:02 CET 2003
Update of /cvsroot/nagiosplug/nagiosplug/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv11770
Added Files:
mail_error
Log Message:
Sends email if non-zero return code from command
--- NEW FILE ---
#!/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
More information about the Commits
mailing list