From 9e335224a023e62b3c6530e38e02f6bcbc291aa5 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Thu, 23 May 2019 23:07:44 -0600 Subject: [PATCH] func exitError for consistent error logging --- backup_new.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backup_new.sh b/backup_new.sh index a17c1ce..6bbd6d4 100755 --- a/backup_new.sh +++ b/backup_new.sh @@ -35,6 +35,19 @@ badParam () { fi } +exitError () { + errCode="error_$1" + eval errReport='$'"$errCode" + if [ -n "$errReport" ]; then + printf "${err}[%s] -- [ERROR] %s: %s --${norm}\n" \ + "$(stamp)" "$1" "$errReport" >> "$logFile" + else + printf "${err}[%s] -- [ERROR] Unknown error code reported --${norm}\n" \ + "$(stamp)" >> "$logFile" + fi + exit "$1" +} + # control seafile services (systemd) seafSvc () { if [ "$1" = "start" ]; then