Quit function added with error code reporting

This commit is contained in:
Asif Bacchus 2018-09-06 00:37:21 -06:00
parent 9fed8511ee
commit dbfd5f64a0

View File

@ -124,13 +124,37 @@ if [ $(id -u) -ne 0 ]; then
fi fi
### elevate script -- used during program testing ## elevate script -- used during program testing
#if [ $EUID != 0 ]; then #if [ $EUID != 0 ]; then
# sudo "$0" "$@" # sudo "$0" "$@"
# exit $? # exit $?
#fi #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 ## Write script execution start in log file
echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \ echo -e "\e[1;32m[`date +%Y-%m-%d` `date +%H:%M:%S`]" \
"--Begin backup operations--\e[0m" >> $logFile "--Begin backup operations--\e[0m" >> $logFile