mail_wrap_script.sh: add --always-send flag

This commit is contained in:
Alice Gaudon 2020-04-15 06:47:16 +02:00
parent fd57e42957
commit bb8cf9ffa8

View File

@ -3,11 +3,22 @@
# Default values # Default values
IGNORE_EXIST_CODE=0 IGNORE_EXIST_CODE=0
SCRIPT="-1" SCRIPT="-1"
ALWAYS_SEND=0
# Get arguments # Get arguments
while [ $# -gt 1 ]; do while [ $# -gt 1 ]; do
# single ARG
ARG_NAME=$1 ARG_NAME=$1
shift shift
case $ARG_NAME in
--always-send)
ALWAYS_SEND=1
continue
;;
esac
# ARG + VALUE
ARG_VALUE=$1 ARG_VALUE=$1
shift shift
@ -43,7 +54,7 @@ OUTPUT=$(cat /tmp/$FILE_ID.log)
rm /tmp/$FILE_ID.log rm /tmp/$FILE_ID.log
# Send mail in case of error # Send mail in case of error
if [ $ERR -ne 0 ] && [ "$ERR" != "$IGNORE_EXIT_CODE" ]; then if [ $ALWAYS_SEND -ne 0 ] || [ $ERR -ne 0 ] && [ "$ERR" != "$IGNORE_EXIT_CODE" ]; then
echo "Sending error mail" 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 -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 "Sent"