mail_wrap_script.sh: directly output to stdout with tee
This commit is contained in:
parent
e4b1845015
commit
a3ad594ca8
@ -4,14 +4,16 @@ SCRIPT=$1
|
|||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
OUTPUT=$($SCRIPT "$@" 2>&1)
|
$SCRIPT "$@" 2>&1 | tee /tmp/backup.log
|
||||||
|
ERR=$?
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
OUTPUT=$(cat /tmp/backup.log)
|
||||||
|
rm /tmp/backup.log
|
||||||
|
|
||||||
|
if [ $ERR -ne 0 ]; then
|
||||||
MAILTO=$(cat "$HOME/.admin_mail")
|
MAILTO=$(cat "$HOME/.admin_mail")
|
||||||
echo "Sending error mail"
|
echo "Sending error mail"
|
||||||
echo -e "An error occured during the execution of $SCRIPT.\n\n$OUTPUT" | mailx -s "$(hostname) $SCRIPT failure" "$MAILTO"
|
echo -e "An error occured during the execution of $SCRIPT.\n\n$OUTPUT" | mailx -s "$(hostname) $SCRIPT failure" "$MAILTO"
|
||||||
echo "Sent"
|
echo "Sent"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
|
||||||
echo -e "$OUTPUT"
|
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user