From 4eee202c5ebcda9dff4d80299f06d6db4f8185ff Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Wed, 19 Sep 2018 15:36:57 -0600 Subject: [PATCH] Added quit function --- backup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backup.sh b/backup.sh index be5e9cc..8df5adb 100755 --- a/backup.sh +++ b/backup.sh @@ -21,6 +21,23 @@ function scriptHelp { quit 98 } +### quit -- exit the script after logging any errors, warnings, etc. and +### cleaning up as necessary +function quit { + if [ -z "$1" ]; then + # exit cleanly + echo -e "${bold}${green}${stamp} -- [SUCCESS] Script completed" \ + "--$normal" + exit 0 + else + # log error code and exit with said code + echo -e "${bold}${red}${stamp} -- [ERROR] Script exited with code $1" \ + " --$normal" + echo -e "${red}${errorExplain[$1]}$normal" + exit "$1" + fi +} + ### End of Functions ###