From a308700086905b53d1f9da13808586be93c4a653 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Fri, 7 Sep 2018 03:23:16 -0600 Subject: [PATCH] Added exitError array for deferred exit. Critical errors, but still had to cleanup. --- root/scripts/borgbackup.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/root/scripts/borgbackup.sh b/root/scripts/borgbackup.sh index f30064f..d9a4a23 100755 --- a/root/scripts/borgbackup.sh +++ b/root/scripts/borgbackup.sh @@ -162,12 +162,17 @@ function quit { elif [ "$2" = "warn" ]; then # exit with warning code echo -e "\e[1;33m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ - "--Script exiting with WARNING(S) (code: ${exitWarning[*]})--\e[0m" >> $logFile + "--Script exited with WARNING(S) (code: ${exitWarning[*]})--\e[0m" >> $logFile + exit "$1" + elif [ $"2" = "error" ]; then + # this is a deferred exit, codes need to be listed + echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ + "--Script exited with ERROR(S) (code: ${exitError[*]})--\e[0m" >> $logFile exit "$1" else - # exit with error code + # exit immediately with error code echo -e "\e[1;31m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ - "--Script exiting with ERROR (code: $1)--\e[0m" >> $logFile + "--Script exited with ERROR (code: $1)--\e[0m" >> $logFile exit "$1" fi } @@ -225,6 +230,7 @@ echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ scriptPath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" err503FullPath="$scriptPath/$err503FileName" exitWarning=() +exitError=() ## Determine verbosity level for logging if [ "$1" = "verbose" ]; then @@ -451,6 +457,8 @@ fi ## Log completion of script if [ ${#exitWarning[@]} -gt 0 ]; then quit 101 warn +elif [ ${#exitError[@]} -gt 0 ]; then + quit 100 error else quit fi