Updated ofunctions from obackup
This commit is contained in:
parent
9e5a2c82f1
commit
6fc4bef224
|
@ -3,11 +3,12 @@
|
||||||
#### OFUNCTIONS MINI SUBSET ####
|
#### OFUNCTIONS MINI SUBSET ####
|
||||||
|
|
||||||
_OFUNCTIONS_VERSION=2.1-RC1+dev
|
_OFUNCTIONS_VERSION=2.1-RC1+dev
|
||||||
_OFUNCTIONS_BUILD=2016122701
|
_OFUNCTIONS_BUILD=2017010401
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET ####
|
||||||
_OFUNCTIONS_BOOTSTRAP=true
|
_OFUNCTIONS_BOOTSTRAP=true
|
||||||
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
#### _OFUNCTIONS_BOOTSTRAP SUBSET END ####
|
||||||
## 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-2017 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:
|
||||||
## PROGRAM=program-name
|
## PROGRAM=program-name
|
||||||
|
@ -586,7 +587,7 @@ function TrapError {
|
||||||
local code="${2:-1}"
|
local code="${2:-1}"
|
||||||
|
|
||||||
if [ $_LOGGER_SILENT == false ]; then
|
if [ $_LOGGER_SILENT == false ]; then
|
||||||
echo -e "\e[45m/!\ ERROR in ${job}: Near line ${line}, exit code ${code}\e[0m"
|
(>&2 echo -e "\e[45m/!\ ERROR in ${job}: Near line ${line}, exit code ${code}\e[0m")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#### TrapError SUBSET END ####
|
#### TrapError SUBSET END ####
|
||||||
|
@ -680,7 +681,7 @@ function WaitForTaskCompletion {
|
||||||
Spinner
|
Spinner
|
||||||
fi
|
fi
|
||||||
if [ $counting == true ]; then
|
if [ $counting == true ]; then
|
||||||
exec_time=$(($SECONDS - $seconds_begin))
|
exec_time=$((SECONDS - seconds_begin))
|
||||||
else
|
else
|
||||||
exec_time=$SECONDS
|
exec_time=$SECONDS
|
||||||
fi
|
fi
|
||||||
|
@ -836,7 +837,7 @@ function ParallelExec {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $counting == true ]; then
|
if [ $counting == true ]; then
|
||||||
exec_time=$(($SECONDS - $seconds_begin))
|
exec_time=$((SECONDS - seconds_begin))
|
||||||
else
|
else
|
||||||
exec_time=$SECONDS
|
exec_time=$SECONDS
|
||||||
fi
|
fi
|
||||||
|
@ -874,7 +875,7 @@ function ParallelExec {
|
||||||
fi
|
fi
|
||||||
eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=true"
|
eval "HARD_MAX_EXEC_TIME_REACHED_$callerName=true"
|
||||||
# Return the number of commands that haven't run / finished run
|
# Return the number of commands that haven't run / finished run
|
||||||
return $(($commandCount - $counter + ${#pidsArray[@]}))
|
return $((commandCount - counter + ${#pidsArray[@]}))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ $counter -lt "$commandCount" ] && [ ${#pidsArray[@]} -lt $numberOfProcesses ]; do
|
while [ $counter -lt "$commandCount" ] && [ ${#pidsArray[@]} -lt $numberOfProcesses ]; do
|
||||||
|
@ -897,7 +898,6 @@ function ParallelExec {
|
||||||
if [ $(IsInteger $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="$(eval $PROCESS_STATE_CMD)"
|
pidState="$(eval $PROCESS_STATE_CMD)"
|
||||||
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
|
if [ "$pidState" != "D" ] && [ "$pidState" != "Z" ]; then
|
||||||
newPidsArray+=($pid)
|
newPidsArray+=($pid)
|
||||||
|
@ -921,7 +921,7 @@ function ParallelExec {
|
||||||
pidsArray=("${newPidsArray[@]}")
|
pidsArray=("${newPidsArray[@]}")
|
||||||
|
|
||||||
# Trivial wait time for bash to not eat up all CPU
|
# Trivial wait time for bash to not eat up all CPU
|
||||||
sleep $SLEEP_TIME
|
sleep $sleepTime
|
||||||
done
|
done
|
||||||
|
|
||||||
return $errorCount
|
return $errorCount
|
||||||
|
@ -937,11 +937,6 @@ function CleanUp {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# obsolete, use StripQuotes
|
|
||||||
function SedStripQuotes {
|
|
||||||
echo $(echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
|
|
||||||
}
|
|
||||||
|
|
||||||
# Usage: var=$(StripSingleQuotes "$var")
|
# Usage: var=$(StripSingleQuotes "$var")
|
||||||
function StripSingleQuotes {
|
function StripSingleQuotes {
|
||||||
local string="${1}"
|
local string="${1}"
|
||||||
|
@ -1423,8 +1418,8 @@ function __CheckArguments {
|
||||||
if [ "$argument" == "" ]; then
|
if [ "$argument" == "" ]; then
|
||||||
fetchArguments=false
|
fetchArguments=false
|
||||||
else
|
else
|
||||||
argList="$argList[Argument $(($iterate-2)): $argument] "
|
argList="$argList[Argument $((iterate-2)): $argument] "
|
||||||
iterate=$(($iterate+1))
|
iterate=$((iterate+1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -1440,7 +1435,7 @@ function __CheckArguments {
|
||||||
Logger "Entering function [$callerName]." "PARANOIA_DEBUG"
|
Logger "Entering function [$callerName]." "PARANOIA_DEBUG"
|
||||||
|
|
||||||
if ! ([ $countedArguments -ge $minArgs ] && [ $countedArguments -le $maxArgs ]); then
|
if ! ([ $countedArguments -ge $minArgs ] && [ $countedArguments -le $maxArgs ]); then
|
||||||
Logger "Function $functionName may have inconsistent number of arguments. Expected min: $minArgs, max: $maxArgs, count: $countedArguments, bash seen: $numberOfGivenArguments. see log file." "ERROR"
|
Logger "Function $callerName may have inconsistent number of arguments. Expected min: $minArgs, max: $maxArgs, count: $countedArguments, bash seen: $numberOfGivenArguments." "ERROR"
|
||||||
Logger "$callerName arguments: $argList" "ERROR"
|
Logger "$callerName arguments: $argList" "ERROR"
|
||||||
else
|
else
|
||||||
if [ ! -z "$argList" ]; then
|
if [ ! -z "$argList" ]; then
|
||||||
|
|
Loading…
Reference in New Issue