diff --git a/mail_wrap_script.sh b/mail_wrap_script.sh index 8d8ae69..7b11349 100755 --- a/mail_wrap_script.sh +++ b/mail_wrap_script.sh @@ -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