mail_wrap_script.sh: improve handling of too long mail body

This commit is contained in:
Alice Gaudon 2022-09-16 09:16:34 +00:00
parent e7769419b1
commit 8164888ad9
1 changed files with 18 additions and 4 deletions

View File

@ -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