rework code for email and notifications (more DRY)
This commit is contained in:
parent
279a5580fe
commit
f3f4ddcd89
1 changed files with 12 additions and 22 deletions
|
|
@ -858,33 +858,23 @@ esac
|
||||||
|
|
||||||
echo -e "--------- END DUPLICITY-BACKUP SCRIPT ---------\n" >> "${LOGFILE}"
|
echo -e "--------- END DUPLICITY-BACKUP SCRIPT ---------\n" >> "${LOGFILE}"
|
||||||
|
|
||||||
if [ "${EMAIL_FAILURE_ONLY}" = "yes" ]; then
|
# send email
|
||||||
if [ ${BACKUP_ERROR} ]; then
|
if [ "${BACKUP_ERROR}" ]; then
|
||||||
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
|
|
||||||
email_logfile
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ ${BACKUP_ERROR} ]; then
|
|
||||||
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
|
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
|
||||||
else
|
else
|
||||||
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
|
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
|
||||||
fi
|
fi
|
||||||
email_logfile
|
|
||||||
|
[[ ${BACKUP_ERROR} || ! "$EMAIL_FAILURE_ONLY" = "yes" ]] && email_logfile
|
||||||
|
|
||||||
|
# send notification
|
||||||
|
if [ "${BACKUP_ERROR}" ]; then
|
||||||
|
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
|
||||||
|
else
|
||||||
|
NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${NOTIFICATION_FAILURE_ONLY}" = "yes" ]; then
|
[[ ${BACKUP_ERROR} || ! "$NOTIFICATION_FAILURE_ONLY" = "yes" ]] && send_notification
|
||||||
if [ ${BACKUP_ERROR} ]; then
|
|
||||||
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`"
|
|
||||||
send_notification
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ ${BACKUP_ERROR} ]; then
|
|
||||||
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`"
|
|
||||||
else
|
|
||||||
NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`${LOGFILE}\`"
|
|
||||||
fi
|
|
||||||
send_notification
|
|
||||||
fi
|
|
||||||
|
|
||||||
# remove old logfiles
|
# remove old logfiles
|
||||||
# stops them from piling up infinitely
|
# stops them from piling up infinitely
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue