mirror of
https://github.com/deajan/obackup.git
synced 2024-12-25 23:13:41 +01:00
Added Integer test function
This commit is contained in:
parent
65a3a0a19a
commit
cd3da2d589
@ -146,7 +146,7 @@ function CheckCurrentConfig {
|
|||||||
# Check all variables that should contain a numerical value >= 0
|
# 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)
|
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
|
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"
|
eval "$test"
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -279,10 +279,6 @@ function ListDatabases {
|
|||||||
if [ -f "$outputFile" ] && [ $CAN_BACKUP_SQL == true ]; then
|
if [ -f "$outputFile" ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
while read -r name size; do dbName=$name; dbSize=$size; done <<< "$line"
|
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
|
if [ "$DATABASES_ALL" == "yes" ]; then
|
||||||
dbBackup=1
|
dbBackup=1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#### MINIMAL-FUNCTION-SET BEGIN ####
|
#### 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
|
## 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:
|
## To use in a program, define the following variables:
|
||||||
@ -680,7 +680,7 @@ function WaitForTaskCompletion {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for pid in "${pidsArray[@]}"; do
|
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
|
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 ? :)
|
# 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
|
#TODO(high): have this tested on *BSD, Mac & Win
|
||||||
@ -761,7 +761,7 @@ function ParallelExec {
|
|||||||
|
|
||||||
newPidsArray=()
|
newPidsArray=()
|
||||||
for pid in "${pidsArray[@]}"; do
|
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 ? :)
|
# 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
|
if kill -0 $pid > /dev/null 2>&1; then
|
||||||
pidState=$(ps -p$pid -o state= 2 > /dev/null)
|
pidState=$(ps -p$pid -o state= 2 > /dev/null)
|
||||||
@ -837,7 +837,7 @@ function EscapeSpaces {
|
|||||||
echo "${string// /\\ }"
|
echo "${string// /\\ }"
|
||||||
}
|
}
|
||||||
|
|
||||||
function IsNumeric {
|
function IsNumericOld {
|
||||||
eval "local value=\"${1}\"" # Needed eval so variable variables can be processed
|
eval "local value=\"${1}\"" # Needed eval so variable variables can be processed
|
||||||
|
|
||||||
local re="^-?[0-9]+([.][0-9]+)?$"
|
local re="^-?[0-9]+([.][0-9]+)?$"
|
||||||
@ -848,6 +848,26 @@ function IsNumeric {
|
|||||||
fi
|
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
|
## from https://gist.github.com/cdown/1163649
|
||||||
function urlEncode {
|
function urlEncode {
|
||||||
local length="${#1}"
|
local length="${#1}"
|
||||||
|
Loading…
Reference in New Issue
Block a user