From 8f81c85274cd7a21d4bff819bf800b300a7488d2 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 24 Jun 2021 10:40:01 -0400 Subject: [PATCH] Allow for disabling reports by email. This diff simply adds one line: `if [ ! -z "$reportemail" ]; then` and then it indents the if block and adds a final `fi`. This check used to be there, without it, its not possible to disable report mails, which might be something desirable if you are getting alerts through the prometheus method. --- src/backupninja.in | 53 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/backupninja.in b/src/backupninja.in index 8a95b62..b84e436 100755 --- a/src/backupninja.in +++ b/src/backupninja.in @@ -661,36 +661,37 @@ EOF let "errors +-1" fi fi - if [ -x "$(which mail 2>/dev/null)" ]; then - debug "send report to $reportemail" - hostname=`hostname` - [ $warnings == 0 ] || subject="WARNING" - [ $errors == 0 ] || subject="ERROR" - [ $fatals == 0 ] || subject="FAILED" - [ $halts == 0 ] || subject="HALTED" + if [ ! -z "$reportemail" ]; then + if [ -x "$(which mail 2>/dev/null)" ]; then + debug "send report to $reportemail" + hostname=`hostname` + [ $warnings == 0 ] || subject="WARNING" + [ $errors == 0 ] || subject="ERROR" + [ $fatals == 0 ] || subject="FAILED" + [ $halts == 0 ] || subject="HALTED" - { - for ((i=0; i < ${#messages[@]} ; i++)); do - echo ${messages[$i]} - done - echo -e "$errormsg" - if [ "$reportspace" == "yes" ]; then - previous="" - for i in $(ls "$configdirectory"); do - backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}') - if [ "$backuploc" != "$previous" -a -n "$backuploc" -a -d "$backuploc" ]; then - df -h "$backuploc" - previous="$backuploc" - fi + { + for ((i=0; i < ${#messages[@]} ; i++)); do + echo ${messages[$i]} done - fi - } | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail - else - error "Unable to locate mail executable, email report not sent!" - let "errors += 1" + echo -e "$errormsg" + if [ "$reportspace" == "yes" ]; then + previous="" + for i in $(ls "$configdirectory"); do + backuploc=$(grep ^directory "$configdirectory"/"$i" | @AWK@ '{print $3}') + if [ "$backuploc" != "$previous" -a -n "$backuploc" -a -d "$backuploc" ]; then + df -h "$backuploc" + previous="$backuploc" + fi + done + fi + } | fold -s -w "$reportwrap" | mail -s "backupninja: $hostname $subject" $reportemail + else + error "Unable to locate mail executable, email report not sent!" + let "errors += 1" + fi fi fi - if [ $actions_run != 0 ]; then info "FINISHED: $actions_run actions run. $fatals fatal. $errors error. $warnings warning." if [ "$halts" != "0" ]; then