Error check running of mailx.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-29 19:46:48 +00:00
commit db93b48579

View file

@ -81,10 +81,16 @@ source /etc/mail.conf "backups" 2>/dev/null || {
# Make sure BACKUP_MOUNTPOINT is a mountpoint. # Make sure BACKUP_MOUNTPOINT is a mountpoint.
mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || { mountpoint "$BACKUP_MOUNTPOINT" >/dev/null 2>&1 || {
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE" [[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
[[ -n "${EMAIL_TO[*]}" ]] && mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF if [[ -n "${EMAIL_TO[*]}" ]]; then
'$BACKUP_MOUNTPOINT' is not a mountpoint. mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
EOF printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
exit 1 '$BACKUP_MOUNTPOINT' is not a mountpoint.
EOF
exit 1
else
printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2
exit 1
fi
} }
# Do the backup. # Do the backup.
@ -94,15 +100,20 @@ ERR="$?"
# Send a notification and mail a log if there were errors. # Send a notification and mail a log if there were errors.
(( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && { (( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && {
[[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE" [[ -x "/opt/bin/pushover" ]] && CONFIG_FILE="backups" /opt/bin/pushover -T "Backup" -p '-1' -m "Failure: $RSYNC_SOURCE"
[[ -n "${EMAIL_TO[*]}" ]] && mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF if [[ -n "${EMAIL_TO[*]}" ]]; then
Exit code: $ERR mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
Output: printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
$(< "$RSYNC_LOG") Exit code: $ERR
EOF Output:
rm -f "$RSYNC_LOG" $(< "$RSYNC_LOG")
exit 1 EOF
RET=1
else
printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2
RET=1
fi
} }
rm -f "$RSYNC_LOG" rm -f "$RSYNC_LOG"
exit 0 exit "${RET:-0}"