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.
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"
[[ -n "${EMAIL_TO[*]}" ]] && mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF
if [[ -n "${EMAIL_TO[*]}" ]]; then
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
'$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.
@ -94,15 +100,20 @@ ERR="$?"
# Send a notification and mail a log if there were errors.
(( ERR != 0 )) && (( ERR != 10 )) && (( ERR != 24 )) && {
[[ -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
mailx "${MAILX_ARGS[@]}" -S "from='$EMAIL_FROM'" -s "Backup failure: $RSYNC_SOURCE" "${EMAIL_TO[@]}" <<-EOF 2>/dev/null || \
printf "%s: %s\\n" "${0##*/}" "mailx command failed" >&2
Exit code: $ERR
Output:
$(< "$RSYNC_LOG")
EOF
rm -f "$RSYNC_LOG"
exit 1
RET=1
else
printf "%s: %s\\n" "${0##*/}" "no recipient configured for mail delivery" >&2
RET=1
fi
}
rm -f "$RSYNC_LOG"
exit 0
exit "${RET:-0}"