From af70cb2e2f1fb0c26bf612b4f41769ada3a38572 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Wed, 19 Sep 2018 16:04:59 -0600 Subject: [PATCH] Added root check and updated exit codes --- backup.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backup.sh b/backup.sh index cab6563..39efb72 100755 --- a/backup.sh +++ b/backup.sh @@ -19,7 +19,7 @@ stamp="[`date +%Y-%m-%d` `date +%H:%M:%S`]" function scriptHelp { echo "In the future, I will be something helpful!" # exit with code 98 -- there is no use logging this - exit 98 + exit 1 } ### quit -- exit the script after logging any errors, warnings, etc. and @@ -82,6 +82,13 @@ while getopts ':l:' PARAMS; do done +### Verify script running as root, otherwise exit (un-logged) +if [ $(id -u) -ne 0 ]; then + echo -e "${bold}${red}This script must be run as root. Aborted.${normal}" + exit 2 +fi + + ### Log start of script operations echo -e "${bold}${stamp}-- Start $scriptName execution ---" >> "$logFile"