From cd3da2d58925dde8ae9f23304cce600e4b7219f1 Mon Sep 17 00:00:00 2001 From: deajan Date: Sat, 3 Sep 2016 13:10:14 +0200 Subject: [PATCH] Added Integer test function --- dev/n_obackup.sh | 6 +----- dev/ofunctions.sh | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/dev/n_obackup.sh b/dev/n_obackup.sh index 367beb3..69c65f0 100755 --- a/dev/n_obackup.sh +++ b/dev/n_obackup.sh @@ -146,7 +146,7 @@ function CheckCurrentConfig { # Check all variables that should contain a numerical value >= 0 declare -a num_vars=(BACKUP_SIZE_MINIMUM SQL_WARN_MIN_SPACE FILE_WARN_MIN_SPACE SOFT_MAX_EXEC_TIME_DB_TASK HARD_MAX_EXEC_TIME_DB_TASK COMPRESSION_LEVEL SOFT_MAX_EXEC_TIME_FILE_TASK HARD_MAX_EXEC_TIME_FILE_TASK BANDWIDTH SOFT_MAX_EXEC_TIME_TOTAL HARD_MAX_EXEC_TIME_TOTAL ROTATE_SQL_COPIES ROTATE_FILE_COPIES KEEP_LOGGING MAX_EXEC_TIME_PER_CMD_BEFORE MAX_EXEC_TIME_PER_CMD_AFTER) for i in "${num_vars[@]}"; do - test="if [ $(IsNumeric \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it with the update script if using and old version.\" \"CRITICAL\"; exit 1; fi" + test="if [ $(IsInteger \"\$$i\") -eq 0 ]; then Logger \"Bogus $i value defined in config file. Correct your config file or update it with the update script if using and old version.\" \"CRITICAL\"; exit 1; fi" eval "$test" done @@ -279,10 +279,6 @@ function ListDatabases { if [ -f "$outputFile" ] && [ $CAN_BACKUP_SQL == true ]; then while read -r line; do while read -r name size; do dbName=$name; dbSize=$size; done <<< "$line" - #db_name="${line% *}" - #db_size="${line# *}" - #db_name=$(echo $line | cut -f1) - #db_size=$(echo $line | cut -f2) if [ "$DATABASES_ALL" == "yes" ]; then dbBackup=1 diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 38b9226..85d4454 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -1,6 +1,6 @@ #### MINIMAL-FUNCTION-SET BEGIN #### -## FUNC_BUILD=2016090204 +## FUNC_BUILD=2016090301 ## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr ## To use in a program, define the following variables: @@ -680,7 +680,7 @@ function WaitForTaskCompletion { fi for pid in "${pidsArray[@]}"; do - if [ $(IsNumeric $pid) -eq 1 ]; then + if [ $(IsInteger $pid) -eq 1 ]; then if kill -0 $pid > /dev/null 2>&1; then # Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :) #TODO(high): have this tested on *BSD, Mac & Win @@ -761,7 +761,7 @@ function ParallelExec { newPidsArray=() for pid in "${pidsArray[@]}"; do - if [ $(IsNumeric $pid) -eq 1 ]; then + if [ $(IsInteger $pid) -eq 1 ]; then # Handle uninterruptible sleep state or zombies by ommiting them from running process array (How to kill that is already dead ? :) if kill -0 $pid > /dev/null 2>&1; then pidState=$(ps -p$pid -o state= 2 > /dev/null) @@ -837,7 +837,7 @@ function EscapeSpaces { echo "${string// /\\ }" } -function IsNumeric { +function IsNumericOld { eval "local value=\"${1}\"" # Needed eval so variable variables can be processed local re="^-?[0-9]+([.][0-9]+)?$" @@ -848,6 +848,26 @@ function IsNumeric { fi } +function IsNumeric { + local value="${1}" + + if [[ $value =~ ^[0-9]+([.][0-9]+)?$ ]]; then + echo 1 + else + echo 0 + fi +} + +function IsInteger { + local value="${1}" + + if [[ $value =~ ^[0-9]?$ ]]; then + echo 1 + else + echo 0 + fi +} + ## from https://gist.github.com/cdown/1163649 function urlEncode { local length="${#1}"