From 4d1a10152b72c316cde0b1ec66f933d84d0316e8 Mon Sep 17 00:00:00 2001 From: Baptiste Bouchereau Date: Mon, 5 Sep 2022 10:21:32 -0700 Subject: [PATCH] Rename error handler function --- backup_script.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backup_script.sh b/backup_script.sh index ca34341..9fd4936 100644 --- a/backup_script.sh +++ b/backup_script.sh @@ -1,6 +1,6 @@ #!/bin/bash -send_email() { +send_email_on_error() { ansible-playbook /var/smtp-email-playbook/main.yml \ -e "smtp_user=$SMTP_USER" \ -e "smtp_password=$SMTP_PASSWORD" \ @@ -11,9 +11,10 @@ send_email() { -e "mail_subject='$MAIL_SUBJECT'" } +# Only handle errors if the required environment variables are defined to send an email if [[ ! -z "$SMTP_USER" && ! -z "$SMTP_PASSWORD" && ! -z "$SMTP_PORT" && ! -z "$SMTP_HOST" && ! -z "$MAIL_TO" && ! -z "$MAIL_BODY" && ! -z "$MAIL_SUBJECT" ]]; then set -o errexit -o errtrace - trap send_email ERR + trap send_email_on_error ERR fi if [[ ! -z "$MYSQL_USER" && ! -z "$MYSQL_DATABASE" && ! -z "$MYSQL_PASSWORD" && ! -z "$MYSQL_HOST" ]]; then