mail_wrap_script.sh: directly output to stdout with tee

This commit is contained in:
Alice Gaudon 2020-01-29 04:00:04 +01:00
parent e4b1845015
commit a3ad594ca8

View File

@ -4,14 +4,16 @@ SCRIPT=$1
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")
echo "Sending error mail"
echo -e "An error occured during the execution of $SCRIPT.\n\n$OUTPUT" | mailx -s "$(hostname) $SCRIPT failure" "$MAILTO"
echo "Sent"
exit 1
else
echo -e "$OUTPUT"
fi