From dbfd5f64a0d728062b5f284ed4bfdbcdb8ed49cc Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Thu, 6 Sep 2018 00:37:21 -0600 Subject: [PATCH] Quit function added with error code reporting --- root/scripts/borgbackup.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/root/scripts/borgbackup.sh b/root/scripts/borgbackup.sh index 6d58fe8..87daaa6 100755 --- a/root/scripts/borgbackup.sh +++ b/root/scripts/borgbackup.sh @@ -124,13 +124,37 @@ if [ $(id -u) -ne 0 ]; then fi -### elevate script -- used during program testing +## elevate script -- used during program testing #if [ $EUID != 0 ]; then # sudo "$0" "$@" # exit $? #fi +### Functions: + +function quit { + if [ -z "$1" ]; then + # exit gracefully + echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ + "--Backup operations completed SUCCESSFULLY--\e[0m" >> $logFile + exit 0 + 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 (code: $1)--\e[0m" >> $logFile + exit "$1" + else + # exit 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 + exit "$1" + fi +} + +### End of functions + + ## Write script execution start in log file echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ "--Begin backup operations--\e[0m" >> $logFile