summaryrefslogtreecommitdiffstats
path: root/tools/mail_error
blob: 184827e92e24dba93e3779d83645b48408676ec9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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))

[[ -z $1 ]] && die "Must specify command"

if ! "$@" > $output_file 2>&1 ; then
	mail -s "mail_error fail: $1" $email < $output_file
fi