Error check running of mailx.
This commit is contained in:
parent
d0cf34c101
commit
db93b48579
1 changed files with 23 additions and 12 deletions
35
do-backup
35
do-backup
|
|
@ -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
|
||||
'$BACKUP_MOUNTPOINT' is not a mountpoint.
|
||||
EOF
|
||||
exit 1
|
||||
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
|
||||
Exit code: $ERR
|
||||
Output:
|
||||
$(< "$RSYNC_LOG")
|
||||
EOF
|
||||
rm -f "$RSYNC_LOG"
|
||||
exit 1
|
||||
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
|
||||
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}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue