2003-03-23 21:21:02 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
# mail_error -o file -m email_address command
|
2003-03-23 21:57:50 -05:00
|
|
|
# Runs command from cron and redirects all output to file
|
|
|
|
|
# If command rc != 0, sends output to email_address
|
2003-03-23 21:21:02 -05:00
|
|
|
|
|
|
|
|
function die { echo $1 ; exit 1; }
|
|
|
|
|
|
2003-10-15 15:27:56 -04:00
|
|
|
# Must be export so that sfsnapshot uses correct versions
|
|
|
|
|
# of GNU toolchain
|
|
|
|
|
export PATH=$HOME/bin:$HOME/local/bin:$PATH
|
2003-03-23 21:57:50 -05:00
|
|
|
|
2003-03-23 21:21:02 -05:00
|
|
|
while getopts "o:m:" c; do
|
|
|
|
|
case $c in
|
|
|
|
|
o) output_file=$OPTARG;;
|
|
|
|
|
m) email=$OPTARG;;
|
|
|
|
|
\*) echo "oops";;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
shift $(($OPTIND-1))
|
|
|
|
|
|
|
|
|
|
[[ -z $1 ]] && die "Must specify command"
|
|
|
|
|
|
|
|
|
|
if ! "$@" > $output_file 2>&1 ; then
|
2003-03-23 21:44:17 -05:00
|
|
|
mail -s "mail_error fail: $1" $email < $output_file
|
2003-03-23 21:21:02 -05:00
|
|
|
fi
|