rework code for email and notifications (more DRY)

This commit is contained in:
zertrin 2016-03-28 23:46:40 +02:00
parent 279a5580fe
commit f3f4ddcd89

View file

@ -858,34 +858,24 @@ 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_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
email_logfile
fi
else else
if [ ${BACKUP_ERROR} ]; then EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
EMAIL_SUBJECT="BACKUP ERROR: ${EMAIL_SUBJECT}"
else
EMAIL_SUBJECT="BACKUP OK: ${EMAIL_SUBJECT}"
fi
email_logfile
fi fi
if [ "${NOTIFICATION_FAILURE_ONLY}" = "yes" ]; then [[ ${BACKUP_ERROR} || ! "$EMAIL_FAILURE_ONLY" = "yes" ]] && email_logfile
if [ ${BACKUP_ERROR} ]; then
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`" # send notification
send_notification if [ "${BACKUP_ERROR}" ]; then
fi NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
else else
if [ ${BACKUP_ERROR} ]; then NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`"
NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`${LOGFILE}\`"
else
NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`${LOGFILE}\`"
fi
send_notification
fi fi
[[ ${BACKUP_ERROR} || ! "$NOTIFICATION_FAILURE_ONLY" = "yes" ]] && send_notification
# remove old logfiles # remove old logfiles
# stops them from piling up infinitely # stops them from piling up infinitely
[[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find "${LOGDIR}" -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete [[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find "${LOGDIR}" -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete