Oops - this line shouldn't have been here (doesn't even work anyways) ;)
[monitoring-plugins.git] / tools / mail_error
blobaabb579ce744f55778a29b0c5d867ffb6098a18c
1 #!/bin/bash
2 # mail_error -o file -m email_address command
3 # Runs command from cron and redirects all output to file
4 # If command rc != 0, sends output to email_address
6 function die { echo $1 ; exit 1; }
8 # Must be export so that sfsnapshot uses correct versions
9 # of GNU toolchain
10 export PATH=$HOME/bin:$HOME/local/bin:$PATH
12 while getopts "o:m:" c; do
13 case $c in
14 o) output_file=$OPTARG;;
15 m) email=$OPTARG;;
16 \*) echo "oops";;
17 esac
18 done
19 shift $(($OPTIND-1))
21 [[ -z $1 ]] && die "Must specify command"
23 if ! "$@" > $output_file 2>&1 ; then
24 mail -s "mail_error fail: $1" $email < $output_file