diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2003-03-24 02:21:02 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2003-03-24 02:21:02 +0000 |
commit | 75264bc16a77ee1ebfcb9859e649c3cf0dc2fee5 (patch) | |
tree | 9ee98a7b17b9a04a51f1378e6bb81514ef111d06 /tools/mail_error | |
parent | 38ffa48b64165325a2eb4a625cbb05e1dfb0d348 (diff) | |
download | monitoring-plugins-75264bc16a77ee1ebfcb9859e649c3cf0dc2fee5.tar.gz |
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
Diffstat (limited to 'tools/mail_error')
-rwxr-xr-x | tools/mail_error | 22 |
1 files changed, 22 insertions, 0 deletions
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 @@ | |||
1 | #!/bin/bash | ||
2 | # mail_error -o file -m email_address command | ||
3 | # Runs command and redirects all output to file | ||
4 | # If command rc != 0, sends file to email_address | ||
5 | |||
6 | function die { echo $1 ; exit 1; } | ||
7 | |||
8 | while getopts "o:m:" c; do | ||
9 | case $c in | ||
10 | o) output_file=$OPTARG;; | ||
11 | m) email=$OPTARG;; | ||
12 | \*) echo "oops";; | ||
13 | esac | ||
14 | done | ||
15 | shift $(($OPTIND-1)) | ||
16 | echo "output_file=$output_file email=$email" | ||
17 | |||
18 | [[ -z $1 ]] && die "Must specify command" | ||
19 | |||
20 | if ! "$@" > $output_file 2>&1 ; then | ||
21 | mail -s "mail_error fail: $@" $email < $output_file | ||
22 | fi | ||