Don't emit an error when there's no email sender and/or recipient.

This commit is contained in:
Darren 'Tadgy' Austin 2026-05-21 19:23:48 +01:00
commit be4d10eeba

View file

@ -1,5 +1,5 @@
#!/bin/bash
# Version: 0.2.0
# Version: 0.2.1
# Copyright (c) 2023-2026:
# Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
@ -17,15 +17,12 @@ EMAIL_TO=("Systems' Administrator <sysadmin@slackware.uk>")
# Functions
notify() {
if [[ -n "$EMAIL_FROM" ]] && (( "${#EMAIL_TO[@]}" != 0 )); then
[[ -n "$EMAIL_FROM" ]] && (( "${#EMAIL_TO[@]}" != 0 )) && {
printf "%s: %s\\n%s: %s\\n%s:\\n%s\\n" "Exit code" "$ERR" "Logfile" "$LOGSDIR/$LOGFILE.xz" "Output" "$(<"$LOGSDIR/$LOGFILE")" | mail -r "$EMAIL_FROM" -s "Mirroring $1" "${EMAIL_TO[@]}" >/dev/null 2>&1 || {
printf "%s: %s\\n" "${0##*/}" "mail command failed" >&2
return 1
}
else
printf "%s: %s\\n" "${0##*/}" "no sender and/or recipient configured for mail delivery" >&2
return 1
fi
}
return 0
}