mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-02-21 17:05:31 -05:00
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
This commit is contained in:
parent
38ffa48b64
commit
75264bc16a
1 changed files with 22 additions and 0 deletions
22
tools/mail_error
Executable file
22
tools/mail_error
Executable file
|
|
@ -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
|
||||
Loading…
Reference in a new issue