Logger "Cannot send mail via $(type -p mail) with attachments !!!""WARN"
@ -573,30 +588,30 @@ function Spinner {
return0
fi
case$toggle
case$_OFUNCTIONS_SPINNER_TOGGLE
in
1)
echo -n " \ "
echo -ne "\r"
toggle="2"
_OFUNCTIONS_SPINNER_TOGGLE=2
;;
2)
echo -n " | "
echo -ne "\r"
toggle="3"
_OFUNCTIONS_SPINNER_TOGGLE=3
;;
3)
echo -n " / "
echo -ne "\r"
toggle="4"
_OFUNCTIONS_SPINNER_TOGGLE=4
;;
*)
echo -n " - "
echo -ne "\r"
toggle="1"
_OFUNCTIONS_SPINNER_TOGGLE=1
;;
esac
}
@ -611,16 +626,21 @@ function joinString {
# Fills a global variable called WAIT_FOR_TASK_COMPLETION that contains list of failed pids in format pid1:result1;pid2:result2
# Warning: Don't imbricate this function into another run if you plan to use the global variable output
# Standard wait $! emulation would be WaitForTaskCompletion $! 0 0 1 0 true false true "${FUNCNAME[0]}"
function WaitForTaskCompletion {
localpids="${1}"# pids to wait for, separated by semi-colon
localsoftMaxTime="${2}"# If program with pid $pid takes longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${3}"# If program with pid $pid takes longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localcallerName="${4}"# Who called this function
localcounting="${5:-true}"# Count time since function has been launched if true, since script has been launched if false
localkeepLogging="${6:-0}"# Log a standby message every X seconds. Set to zero to disable logging
localsoftMaxTime="${2:-0}"# If process(es) with pid(s) $pids take longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${3:-0}"# If process(es) with pid(s) $pids take longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localsleepTime="${4:-.05}"# Seconds between each state check, the shorter this value, the snappier it will be, but as a tradeoff cpu power will be used (general values between .05 and 1).
localkeepLogging="${5:-0}"# Every keepLogging seconds, an alive log message is send. Setting this value to zero disables any alive logging.
localcounting="${6:-true}"# Count time since function has been launched (true), or since script has been launched (false)
localspinner="${7:-true}"# Show spinner (true), don't show anything (false)
localnoError="${8:-false}"# Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
localcallerName="${9}"# Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
Logger "${FUNCNAME[0]} called by [$callerName].""PARANOIA_DEBUG"#__WITH_PARANOIA_DEBUG
Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution.""ERROR"
if[$noError !=true];then
Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution.""ERROR"
fi
for pid in "${pidsArray[@]}";do
KillChilds $pid true
if[$?==0];then
@ -681,7 +705,9 @@ function WaitForTaskCompletion {
Logger "Could not stop task with pid [$pid].""ERROR"
fi
done
SendAlert true
if[$noError !=true];then
SendAlert true
fi
fi
fi
@ -717,7 +743,7 @@ function WaitForTaskCompletion {
pidsArray=("${newPidsArray[@]}")
# Trivial wait time for bash to not eat up all CPU
sleep $SLEEP_TIME
sleep $sleepTime
done
Logger "${FUNCNAME[0]} ended for [$callerName] using [$pidCount] subprocesses with [$errorcount] errors.""PARANOIA_DEBUG"#__WITH_PARANOIA_DEBUG
@ -733,17 +759,28 @@ function WaitForTaskCompletion {
# Take a list of commands to run, runs them sequentially with numberOfProcesses commands simultaneously runs
# Returns the number of non zero exit codes from commands
# Use cmd1;cmd2;cmd3 syntax for small sets, use file for large command sets
# Only 2 first arguments are mandatory
function ParallelExec {
localnumberOfProcesses="${1}"# Number of simultaneous commands to run
localcommandsArg="${2}"# Semi-colon separated list of commands, or file containing one command per line
localreadFromFile="${3:-false}"# Is commandsArg a file or a string ?
localsoftMaxTime="${4:-0}"
localhardMaxTime="${5:-0}"
localcallerName="${6}"# Who called this function
localcounting="${7:-true}"# Count time since function has been launched if true, since script has been launched if false
localkeepLogging="${8:-0}"# Log a standby message every X seconds. Set to zero to disable logging
localnumberOfProcesses="${1}"# Number of simultaneous commands to run
localcommandsArg="${2}"# Semi-colon separated list of commands, or path to file containing one command per line
localreadFromFile="${3:-false}"# commandsArg is a file (true), or a string (false)
localsoftMaxTime="${4:-0}"# If process(es) with pid(s) $pids take longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${5:-0}"# If process(es) with pid(s) $pids take longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localsleepTime="${6:-.05}"# Seconds between each state check, the shorter this value, the snappier it will be, but as a tradeoff cpu power will be used (general values between .05 and 1).
localkeepLogging="${7:-0}"# Every keepLogging seconds, an alive log message is send. Setting this value to zero disables any alive logging.
localcounting="${8:-true}"# Count time since function has been launched (true), or since script has been launched (false)
localspinner="${9:-false}"# Show spinner (true), don't show spinner (false)
localnoError="${10:-false}"# Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
localcallerName="${11:-false}"# Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
# 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
echo"--path=/path/to/conf Path to osync / obackup conf files, defaults to /etc/osync or /etc/obackup"
echo"--max-runs=X Number of max runs per instance, (defaults to 3)"
echo"--max-exec-time=X Retry failed instances only if max execution time not reached (defaults to 36000 seconds). Set to 0 to bypass execution time check"
echo"--no-maxtime Run osync / obackup without honoring conf file defined timeouts"
echo"--dry Will run osync / obackup without actually doing anything; just testing"
echo"--silent Will run osync / obackup without any output to stdout, used for cron jobs"
Logger "Cannot send mail via $(type -p mail) with attachments !!!""WARN"
@ -522,30 +537,30 @@ function Spinner {
return0
fi
case$toggle
case$_OFUNCTIONS_SPINNER_TOGGLE
in
1)
echo -n " \ "
echo -ne "\r"
toggle="2"
_OFUNCTIONS_SPINNER_TOGGLE=2
;;
2)
echo -n " | "
echo -ne "\r"
toggle="3"
_OFUNCTIONS_SPINNER_TOGGLE=3
;;
3)
echo -n " / "
echo -ne "\r"
toggle="4"
_OFUNCTIONS_SPINNER_TOGGLE=4
;;
*)
echo -n " - "
echo -ne "\r"
toggle="1"
_OFUNCTIONS_SPINNER_TOGGLE=1
;;
esac
}
@ -560,13 +575,18 @@ function joinString {
# Fills a global variable called WAIT_FOR_TASK_COMPLETION that contains list of failed pids in format pid1:result1;pid2:result2
# Warning: Don't imbricate this function into another run if you plan to use the global variable output
# Standard wait $! emulation would be WaitForTaskCompletion $! 0 0 1 0 true false true "${FUNCNAME[0]}"
function WaitForTaskCompletion {
localpids="${1}"# pids to wait for, separated by semi-colon
localsoftMaxTime="${2}"# If program with pid $pid takes longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${3}"# If program with pid $pid takes longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localcallerName="${4}"# Who called this function
localcounting="${5:-true}"# Count time since function has been launched if true, since script has been launched if false
localkeepLogging="${6:-0}"# Log a standby message every X seconds. Set to zero to disable logging
localsoftMaxTime="${2:-0}"# If process(es) with pid(s) $pids take longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${3:-0}"# If process(es) with pid(s) $pids take longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localsleepTime="${4:-.05}"# Seconds between each state check, the shorter this value, the snappier it will be, but as a tradeoff cpu power will be used (general values between .05 and 1).
localkeepLogging="${5:-0}"# Every keepLogging seconds, an alive log message is send. Setting this value to zero disables any alive logging.
localcounting="${6:-true}"# Count time since function has been launched (true), or since script has been launched (false)
localspinner="${7:-true}"# Show spinner (true), don't show anything (false)
localnoError="${8:-false}"# Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
localcallerName="${9}"# Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
localsoft_alert=false# Does a soft alert need to be triggered, if yes, send an alert once
@ -594,7 +614,9 @@ function WaitForTaskCompletion {
while[${#pidsArray[@]} -gt 0];do
newPidsArray=()
Spinner
if[$spinner==true];then
Spinner
fi
if[$counting==true];then
exec_time=$(($SECONDS-$seconds_begin))
else
@ -611,14 +633,16 @@ function WaitForTaskCompletion {
Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution.""ERROR"
if[$noError !=true];then
Logger "Max hard execution time exceeded for task [$callerName] with pids [$(joinString , ${pidsArray[@]})]. Stopping task execution.""ERROR"
fi
for pid in "${pidsArray[@]}";do
KillChilds $pid true
if[$?==0];then
@ -627,7 +651,9 @@ function WaitForTaskCompletion {
Logger "Could not stop task with pid [$pid].""ERROR"
fi
done
SendAlert true
if[$noError !=true];then
SendAlert true
fi
fi
fi
@ -659,7 +685,7 @@ function WaitForTaskCompletion {
pidsArray=("${newPidsArray[@]}")
# Trivial wait time for bash to not eat up all CPU
sleep $SLEEP_TIME
sleep $sleepTime
done
@ -674,16 +700,27 @@ function WaitForTaskCompletion {
# Take a list of commands to run, runs them sequentially with numberOfProcesses commands simultaneously runs
# Returns the number of non zero exit codes from commands
# Use cmd1;cmd2;cmd3 syntax for small sets, use file for large command sets
# Only 2 first arguments are mandatory
function ParallelExec {
localnumberOfProcesses="${1}"# Number of simultaneous commands to run
localcommandsArg="${2}"# Semi-colon separated list of commands, or file containing one command per line
localreadFromFile="${3:-false}"# Is commandsArg a file or a string ?
localsoftMaxTime="${4:-0}"
localhardMaxTime="${5:-0}"
localcallerName="${6}"# Who called this function
localcounting="${7:-true}"# Count time since function has been launched if true, since script has been launched if false
localkeepLogging="${8:-0}"# Log a standby message every X seconds. Set to zero to disable logging
localnumberOfProcesses="${1}"# Number of simultaneous commands to run
localcommandsArg="${2}"# Semi-colon separated list of commands, or path to file containing one command per line
localreadFromFile="${3:-false}"# commandsArg is a file (true), or a string (false)
localsoftMaxTime="${4:-0}"# If process(es) with pid(s) $pids take longer than $softMaxTime seconds, will log a warning, unless $softMaxTime equals 0.
localhardMaxTime="${5:-0}"# If process(es) with pid(s) $pids take longer than $hardMaxTime seconds, will stop execution, unless $hardMaxTime equals 0.
localsleepTime="${6:-.05}"# Seconds between each state check, the shorter this value, the snappier it will be, but as a tradeoff cpu power will be used (general values between .05 and 1).
localkeepLogging="${7:-0}"# Every keepLogging seconds, an alive log message is send. Setting this value to zero disables any alive logging.
localcounting="${8:-true}"# Count time since function has been launched (true), or since script has been launched (false)
localspinner="${9:-false}"# Show spinner (true), don't show spinner (false)
localnoError="${10:-false}"# Log errors when reaching soft / hard max time (false), don't log errors on those triggers (true)
localcallerName="${11:-false}"# Name of the function who called this function for debugging purposes, generally ${FUNCNAME[0]}
localsoft_alert=false# Does a soft alert need to be triggered, if yes, send an alert once
locallog_ttime=0# local time instance for comparaison
localseconds_begin=$SECONDS# Seconds since the beginning of the script
localexec_time=0# Seconds since the beginning of this function
# 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