##### Function Name Is parallel #__WITH_PARANOIA_DEBUG
# GetLocalOS no #__WITH_PARANOIA_DEBUG
@ -44,16 +41,10 @@ IS_STABLE=no
# UnlockReplicas yes #__WITH_PARANOIA_DEBUG
# CleanUp no #__WITH_PARANOIA_DEBUG
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling"
#command line arguments don't take -AaqV for example
_OFUNCTIONS_VERSION=2.3.0-dev
_OFUNCTIONS_BUILD=2018062504
_OFUNCTIONS_VERSION=2.3.0-beta1
_OFUNCTIONS_BUILD=2018080801
_OFUNCTIONS_BOOTSTRAP=true
## 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:
## PROGRAM=program-name
## INSTANCE_ID=program-instance-name
@ -63,8 +54,6 @@ _OFUNCTIONS_BOOTSTRAP=true
## _LOGGER_ERR_ONLY=true/false
## _LOGGER_PREFIX="date"/"time"/""
#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde
## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel
## When called from subprocesses, variable of main process cannot be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP
@ -252,7 +241,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
fi
@ -274,7 +263,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ALWAYS"];then
_Logger"""$prefix$value"
_Logger"""$prefix$value"
return
elif["$level"=="DEBUG"];then
if["$_DEBUG"=="yes"];then
@ -389,7 +378,6 @@ function KillChilds {
fi
ifkill -0 "$pid" > /dev/null 2>&1;then
#TODO: Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
# If text is received as attachment ATT00001.bin or noname, consider adding the following to /etc/mail.rc
#set ttycharset=iso-8859-1
#set sendcharsets=iso-8859-1
#set encoding=8bit
function SendEmail {
localsubject="${1}"
localmessage="${2}"
@ -533,11 +527,16 @@ function SendEmail {
local i
for i in "${destinationMails}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
if["${destinationMails[@]}" !=""];then
for i in "${destinationMails[@]}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
else
Logger "No valid email adresses given.""WARN"
return1
fi
# Prior to sending an email, convert its body if needed
if["$MAIL_BODY_CHARSET" !=""];then
@ -809,33 +808,33 @@ function ParallelExec {
function ExecTasks {
# Mandatory arguments
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
# Optional arguments
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
# Parallelism specific arguments
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
local i
Logger "${FUNCNAME[0]} called by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...].""PARANOIA_DEBUG"#__WITH_PARANOIA_DEBUG
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"#TODO: set this to debug in order to stop complaints
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
if["$functionMode"=="ParallelExec"];then
Logger "Command was [${commandsArrayPid[$pid]}].""ERROR"
fi
@ -1076,22 +1075,22 @@ function ExecTasks {
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
fi
fi
hasPids=true##__WITH_PARANOIA_DEBUG
hasPids=true##__WITH_PARANOIA_DEBUG
fi
done
# hasPids can be false on last iteration in ParallelExec mode
@ -2320,7 +2331,7 @@ function WildcardFileExists () {
fi
}
# If using "include" statements, make sure the script does not get executed unless it's loaded by bootstrap
# If using "include" statements, make sure the script does not get executed unless it's loaded by bootstrap.sh which will replace includes with actual code
_OFUNCTIONS_BOOTSTRAP=true
["$_OFUNCTIONS_BOOTSTRAP" !=true]&&echo"Please use bootstrap.sh to load this dev version of $(basename $0)"&&exit1
@ -2678,7 +2689,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This sims wait $! with timeout
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling"
#command line arguments don't take -AaqV for example
_OFUNCTIONS_VERSION=2.3.0-dev
_OFUNCTIONS_BUILD=2018062504
_OFUNCTIONS_VERSION=2.3.0-beta1
_OFUNCTIONS_BUILD=2018080801
_OFUNCTIONS_BOOTSTRAP=true
## 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:
## PROGRAM=program-name
## INSTANCE_ID=program-instance-name
@ -26,8 +20,6 @@ _OFUNCTIONS_BOOTSTRAP=true
## _LOGGER_ERR_ONLY=true/false
## _LOGGER_PREFIX="date"/"time"/""
#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde
## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel
## When called from subprocesses, variable of main process cannot be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP
@ -215,7 +207,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
fi
@ -237,7 +229,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ALWAYS"];then
_Logger"""$prefix$value"
_Logger"""$prefix$value"
return
elif["$level"=="DEBUG"];then
if["$_DEBUG"=="yes"];then
@ -352,7 +344,6 @@ function KillChilds {
fi
ifkill -0 "$pid" > /dev/null 2>&1;then
#TODO: Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
# If text is received as attachment ATT00001.bin or noname, consider adding the following to /etc/mail.rc
#set ttycharset=iso-8859-1
#set sendcharsets=iso-8859-1
#set encoding=8bit
function SendEmail {
localsubject="${1}"
localmessage="${2}"
@ -496,11 +493,16 @@ function SendEmail {
local i
for i in "${destinationMails}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
if["${destinationMails[@]}" !=""];then
for i in "${destinationMails[@]}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
else
Logger "No valid email adresses given.""WARN"
return1
fi
# Prior to sending an email, convert its body if needed
if["$MAIL_BODY_CHARSET" !=""];then
@ -772,33 +774,33 @@ function ParallelExec {
function ExecTasks {
# Mandatory arguments
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
# Optional arguments
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
# Parallelism specific arguments
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
local i
Logger "${FUNCNAME[0]} called by [${FUNCNAME[0]} < ${FUNCNAME[1]} < ${FUNCNAME[2]} < ${FUNCNAME[3]} < ${FUNCNAME[4]} ...].""PARANOIA_DEBUG"#__WITH_PARANOIA_DEBUG
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"#TODO: set this to debug in order to stop complaints
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
if["$functionMode"=="ParallelExec"];then
Logger "Command was [${commandsArrayPid[$pid]}].""ERROR"
fi
@ -1039,22 +1041,22 @@ function ExecTasks {
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
fi
fi
hasPids=true##__WITH_PARANOIA_DEBUG
hasPids=true##__WITH_PARANOIA_DEBUG
fi
done
# hasPids can be false on last iteration in ParallelExec mode
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling"
#command line arguments don't take -AaqV for example
_OFUNCTIONS_VERSION=2.3.0-dev
_OFUNCTIONS_BUILD=2018062504
_OFUNCTIONS_VERSION=2.3.0-beta1
_OFUNCTIONS_BUILD=2018080801
_OFUNCTIONS_BOOTSTRAP=true
## 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:
## PROGRAM=program-name
## INSTANCE_ID=program-instance-name
@ -34,8 +25,6 @@ _OFUNCTIONS_BOOTSTRAP=true
## _LOGGER_ERR_ONLY=true/false
## _LOGGER_PREFIX="date"/"time"/""
#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde
## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel
## When called from subprocesses, variable of main process cannot be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP
@ -218,7 +207,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
fi
@ -240,7 +229,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ALWAYS"];then
_Logger"""$prefix$value"
_Logger"""$prefix$value"
return
elif["$level"=="DEBUG"];then
if["$_DEBUG"=="yes"];then
@ -345,7 +334,6 @@ function KillChilds {
fi
ifkill -0 "$pid" > /dev/null 2>&1;then
#TODO: Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
# If text is received as attachment ATT00001.bin or noname, consider adding the following to /etc/mail.rc
#set ttycharset=iso-8859-1
#set sendcharsets=iso-8859-1
#set encoding=8bit
function SendEmail {
localsubject="${1}"
localmessage="${2}"
@ -485,11 +479,16 @@ function SendEmail {
local i
for i in "${destinationMails}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
if["${destinationMails[@]}" !=""];then
for i in "${destinationMails[@]}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
else
Logger "No valid email adresses given.""WARN"
return1
fi
# Prior to sending an email, convert its body if needed
if["$MAIL_BODY_CHARSET" !=""];then
@ -744,28 +743,28 @@ function ParallelExec {
function ExecTasks {
# Mandatory arguments
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
# Optional arguments
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
# Parallelism specific arguments
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
local i
@ -791,38 +790,38 @@ function ExecTasks {
IFS=';'read -r -a validExitCodes <<<"$validExitCodes"
# ParallelExec specific variables
localauxItemCount=0# Number of conditional commands
localcommandsArray=()# Array containing commands
localauxItemCount=0 # Number of conditional commands
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"#TODO: set this to debug in order to stop complaints
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
if["$functionMode"=="ParallelExec"];then
Logger "Command was [${commandsArrayPid[$pid]}].""ERROR"
fi
@ -1202,6 +1201,13 @@ function EscapeSpaces {
echo"${string// /\\}"
}
# Usage var=$(EscapeDoubleQuotes "$var") or var="$(EscapeDoubleQuotes "$var")"
function EscapeDoubleQuotes {
localvalue="${1}"
echo"${value//\"/\\\"}"
}
function IsNumericExpand {
eval"local value=\"${1}\""# Needed eval so variable variables can be processed
@ -1290,6 +1296,8 @@ function CheckRFC822 {
function UrlEncode {
locallength="${#1}"
local i
localLANG=C
for i in $(seq 0$((length-1)));do
localc="${1:i:1}"
@ -1510,6 +1518,9 @@ GetOs
ENDSSH
if[$? !=0];then
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT].""CRITICAL"
@ -2169,7 +2180,7 @@ function WildcardFileExists () {
fi
}
# If using "include" statements, make sure the script does not get executed unless it's loaded by bootstrap
# If using "include" statements, make sure the script does not get executed unless it's loaded by bootstrap.sh which will replace includes with actual code
_OFUNCTIONS_BOOTSTRAP=true
["$_OFUNCTIONS_BOOTSTRAP" !=true]&&echo"Please use bootstrap.sh to load this dev version of $(basename $0)"&&exit1
@ -2518,7 +2529,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
# Mac fswatch doesn't have timeout switch, replacing wait $! with WaitForTaskCompletion without warning nor spinner and increased SLEEP_TIME to avoid cpu hogging. This sims wait $! with timeout
#TODO: ExecTasks postponed arrays / files grow a lot. Consider having them "rolling"
#command line arguments don't take -AaqV for example
_OFUNCTIONS_VERSION=2.3.0-dev
_OFUNCTIONS_BUILD=2018062504
_OFUNCTIONS_VERSION=2.3.0-beta1
_OFUNCTIONS_BUILD=2018080801
_OFUNCTIONS_BOOTSTRAP=true
## 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:
## PROGRAM=program-name
## INSTANCE_ID=program-instance-name
@ -26,8 +20,6 @@ _OFUNCTIONS_BOOTSTRAP=true
## _LOGGER_ERR_ONLY=true/false
## _LOGGER_PREFIX="date"/"time"/""
#TODO: global WAIT_FOR_TASK_COMPLETION_id instead of callerName has to be backported to ParallelExec and osync / obackup / pmocr ocde
## Logger sets {ERROR|WARN}_ALERT variable when called with critical / error / warn loglevel
## When called from subprocesses, variable of main process cannot be set. Status needs to be get via $RUN_DIR/$PROGRAM.Logger.{error|warn}.$SCRIPT_PID.$TSTAMP
@ -210,7 +202,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ERROR"];then
_Logger """$prefix\e[91m$value\e[0m" true
_Logger """$prefix\e[31m$value\e[0m" true
if[$_DEBUG=="yes"];then
_Logger -e """[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
fi
@ -232,7 +224,7 @@ function RemoteLogger {
fi
return
elif["$level"=="ALWAYS"];then
_Logger"""$prefix$value"
_Logger"""$prefix$value"
return
elif["$level"=="DEBUG"];then
if["$_DEBUG"=="yes"];then
@ -337,7 +329,6 @@ function KillChilds {
fi
ifkill -0 "$pid" > /dev/null 2>&1;then
#TODO: Warning: pgrep is not native on cygwin, have this checked in CheckEnvironment
# If text is received as attachment ATT00001.bin or noname, consider adding the following to /etc/mail.rc
#set ttycharset=iso-8859-1
#set sendcharsets=iso-8859-1
#set encoding=8bit
function SendEmail {
localsubject="${1}"
localmessage="${2}"
@ -477,11 +474,16 @@ function SendEmail {
local i
for i in "${destinationMails}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
if["${destinationMails[@]}" !=""];then
for i in "${destinationMails[@]}";do
if[$(CheckRFC822 "$i") -ne 1];then
Logger "Given email [$i] does not seem to be valid.""WARN"
fi
done
else
Logger "No valid email adresses given.""WARN"
return1
fi
# Prior to sending an email, convert its body if needed
if["$MAIL_BODY_CHARSET" !=""];then
@ -736,28 +738,28 @@ function ParallelExec {
function ExecTasks {
# Mandatory arguments
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
localmainInput="${1}"# Contains list of pids / commands separated by semicolons or filepath to list of pids / commands
# Optional arguments
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
localid="${2:-base}"# Optional ID in order to identify global variables from this run (only bash variable names, no '-'). Global variables are WAIT_FOR_TASK_COMPLETION_$id and HARD_MAX_EXEC_TIME_REACHED_$id
localreadFromFile="${3:-false}"# Is mainInput / auxInput a semicolon separated list (true) or a filepath (false)
localsoftPerProcessTime="${4:-0}"# Max time (in seconds) a pid or command can run before a warning is logged, unless set to 0
localhardPerProcessTime="${5:-0}"# Max time (in seconds) a pid or command can run before the given command / pid is stopped, unless set to 0
localsoftMaxTime="${6:-0}"# Max time (in seconds) for the whole function to run before a warning is logged, unless set to 0
localhardMaxTime="${7:-0}"# Max time (in seconds) for the whole function to run before all pids / commands given are stopped, unless set to 0
localcounting="${8:-true}"# Should softMaxTime and hardMaxTime be accounted since function begin (true) or since script begin (false)
localsleepTime="${9:-.5}"# Seconds between each state check. The shorter the value, the snappier ExecTasks will be, but as a tradeoff, more cpu power will be used (good values are between .05 and 1)
localkeepLogging="${10:-1800}"# Every keepLogging seconds, an alive message is logged. Setting this value to zero disables any alive logging
localspinner="${11:-true}"# Show spinner (true) or do not show anything (false) while running
localnoTimeErrorLog="${12:-false}"# Log errors when reaching soft / hard execution times (false) or do not log errors on those triggers (true)
localnoErrorLogsAtAll="${13:-false}"# Do not log any errros at all (useful for recursive ExecTasks checks)
# Parallelism specific arguments
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
localnumberOfProcesses="${14:-0}"# Number of simulanteous commands to run, given as mainInput. Set to 0 by default (WaitForTaskCompletion mode). Setting this value enables ParallelExec mode.
localauxInput="${15}"# Contains list of commands separated by semicolons or filepath fo list of commands. Exit code of those commands decide whether main commands will be executed or not
localmaxPostponeRetries="${16:-3}"# If a conditional command fails, how many times shall we try to postpone the associated main command. Set this to 0 to disable postponing
localminTimeBetweenRetries="${17:-300}"# Time (in seconds) between postponed command retries
localvalidExitCodes="${18:-0}"# Semi colon separated list of valid main command exit codes which will not trigger errors
local i
@ -783,38 +785,38 @@ function ExecTasks {
IFS=';'read -r -a validExitCodes <<<"$validExitCodes"
# ParallelExec specific variables
localauxItemCount=0# Number of conditional commands
localcommandsArray=()# Array containing commands
localauxItemCount=0 # Number of conditional commands
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"#TODO: set this to debug in order to stop complaints
Logger "${FUNCNAME[0]} called by [$id] finished monitoring pid [$pid] with exitcode [$retval].""DEBUG"
if["$functionMode"=="ParallelExec"];then
Logger "Command was [${commandsArrayPid[$pid]}].""ERROR"
fi
@ -1194,6 +1196,13 @@ function EscapeSpaces {
echo"${string// /\\}"
}
# Usage var=$(EscapeDoubleQuotes "$var") or var="$(EscapeDoubleQuotes "$var")"
function EscapeDoubleQuotes {
localvalue="${1}"
echo"${value//\"/\\\"}"
}
function IsNumericExpand {
eval"local value=\"${1}\""# Needed eval so variable variables can be processed
@ -1282,6 +1291,8 @@ function CheckRFC822 {
function UrlEncode {
locallength="${#1}"
local i
localLANG=C
for i in $(seq 0$((length-1)));do
localc="${1:i:1}"
@ -1502,6 +1513,9 @@ GetOs
ENDSSH
if[$? !=0];then
Logger "Cannot connect to remote system [$REMOTE_HOST] port [$REMOTE_PORT].""CRITICAL"