diff --git a/mail_wrap_script.sh b/mail_wrap_script.sh index 77e79cd..f118486 100755 --- a/mail_wrap_script.sh +++ b/mail_wrap_script.sh @@ -56,11 +56,25 @@ rm /tmp/$FILE_ID.log # Send mail in case of error if [ $ERR -ne 0 ] && [ "$ERR" != "$IGNORE_EXIT_CODE" ]; then echo "Sending error mail" - echo -e "An error occured during the execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n$OUTPUT" | $(dirname $0)/mail.sh "$(hostname) $SCRIPT failure" - echo "Sent" + echo -e "An error occured during the execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n$OUTPUT" | $(dirname $0)/mail.sh "[E] $(hostname) $SCRIPT" + + if [ $? -eq 0 ]; then + echo "Sent" + else + echo "Could not send mail, sending safe-body mail..." + echo -e "An error occured during the execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n(Could not send full output, see dead.letter)" | $(dirname $0)/mail.sh "[E+M] $(hostname) $SCRIPT" + echo "Sent" + fi exit 1 elif [ $ALWAYS_SEND -ne 0 ]; then echo "Sending log mail" - echo -e "Logging execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n$OUTPUT" | $(dirname $0)/mail.sh "$(hostname) $SCRIPT log" - echo "Sent" + echo -e "Logging execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n$OUTPUT" | $(dirname $0)/mail.sh "[I] $(hostname) $SCRIPT" + + if [ $? -eq 0 ]; then + echo "Sent" + else + echo "Could not send mail, sending safe-body mail..." + echo -e "Logging execution of $SCRIPT ($ERR).\n\n\n$(ps $PPID)\n\n(Could not send full output, see dead.letter)" | $(dirname $0)/mail.sh "[I/M] $(hostname) $SCRIPT" + echo "Sent" + fi fi