diff --git a/dev/ofunctions.sh b/dev/ofunctions.sh index 4ee0e56..5051543 100644 --- a/dev/ofunctions.sh +++ b/dev/ofunctions.sh @@ -3,7 +3,7 @@ #### OFUNCTIONS MINI SUBSET #### _OFUNCTIONS_VERSION=2.2.0-dev -_OFUNCTIONS_BUILD=2018010201 +_OFUNCTIONS_BUILD=2018010302 #### _OFUNCTIONS_BOOTSTRAP SUBSET #### _OFUNCTIONS_BOOTSTRAP=true #### _OFUNCTIONS_BOOTSTRAP SUBSET END #### @@ -700,7 +700,11 @@ function ParallelExec { local spinner="${9:-false}" local noErrorLog="${10:-false}" - ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 3 "$commandsArg" "" "$numberOfProcesses" + if [ $readFromFile == true ]; then + ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 6 "$commandsArg" "" "$numberOfProcesses" + else + ExecTasks "base" 0 0 "$softMaxTime" "$hardMaxTime" "$sleepTime" "$keepLogging" "$counting" "$spinner" "$noErrorLog" false 3 "$commandsArg" "" "$numberOfProcesses" + fi } ## Main asynchronous execution function @@ -754,6 +758,7 @@ function ExecTasks { local counting="${8:-true}" # Count time since function has been launched (true), or since script has been launched (false) local spinner="${9:-true}" # Show spinner (true), do not show anything (false) local noTimeErrorLog="${10:-false}" # Log errors when reaching soft / hard max time (false), do not log errors on those triggers (true) + #TODO not implemented local noErrorLogAtAll="${11:-false}" # Do not log errros at all (false) local execTasksMode="${12:-1}" # In which mode the function should work, see above local mainInput="${13}" # Contains list of pids / commands or filepath to list of pids / commands @@ -782,7 +787,7 @@ function ExecTasks { fi # ParallelExec specific variables - local auxCount # Number of conditional commands + local auxItemCount=0 # Number of conditional commands local commandsArray=() # Array containing commands local commandsConditionArray=() # Array containing conditional commands local currentCommand # Variable containing currently processed command @@ -793,7 +798,7 @@ function ExecTasks { # Common variables local pid # Current pid working on local pidState # State of the process - local mainItemCount # number of given items (pids or commands) + local mainItemCount=0 # number of given items (pids or commands) local readFromFile # Should we read pids / commands from a file (true) local counter=0 local log_ttime=0 # local time instance for comparaison @@ -837,7 +842,6 @@ function ExecTasks { mainItemCount=$(wc -l < "$mainInput") readFromFile=true else - mainItemCount=0 Logger "Cannot read file [$mainInput]." "WARN" fi functionMode=WaitForTaskCompletion @@ -877,7 +881,6 @@ function ExecTasks { mainItemCount=$(wc -l < "$mainInput") readFromFile=true else - mainItemCount=0 Logger "Cannot read file [$mainInput]." "WARN" fi functionMode=ParallelExec @@ -888,13 +891,11 @@ function ExecTasks { mainItemCount=$(wc -l < "$mainInput") readFromFile=true else - mainItemCount=0 Logger "Cannot read file [$mainInput]." "WARN" fi if [ -f "$auxInput" ]; then - auxCount=$(wc -l < "$auxInput") + auxItemCount=$(wc -l < "$auxInput") else - auxCount=0 Logger "Cannot read file [$auxInput]." "WARN" fi postPoneIfConditionFails=false @@ -906,13 +907,11 @@ function ExecTasks { mainItemCount=$(wc -l < "$mainInput") readFromFile=true else - mainItemCount=0 Logger "Cannot read file [$mainInput]." "WARN" fi if [ -f "$auxInput" ]; then - auxCount=$(wc -l < "$auxInput") + auxItemCount=$(wc -l < "$auxInput") else - auxCount=0 Logger "Cannot read file [$auxInput]." "WARN" fi postPoneIfConditionFails=true @@ -989,18 +988,22 @@ function ExecTasks { while [ $counter -lt "$mainItemCount" ] && [ ${#pidsArray[@]} -lt $numberOfProcesses ]; do if [ $readFromFile == true ]; then currentCommand=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$mainInput") - currentCommandCondition=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$auxInput") + if [ $auxItemCount -ne 0 ]; then + currentCommandCondition=$(awk 'NR == num_line {print; exit}' num_line=$((counter+1)) "$auxInput") + fi else - currentCommand="${commandArray[$counter]}" - currentCommandCondition="${commandConditionArray[$counter]}" + currentCommand="${commandsArray[$counter]}" + if [ $auxItemCount -ne 0 ]; then + currentCommandCondition="${commandsConditionArray[$counter]}" + fi fi - executeCommand=false - if [ $auxCount -ne 0 ]; then + if [ $auxItemCount -ne 0 ]; then Logger "Checking condition [$currentCommandCondition] for command [$currentCommand]." "DEBUG" eval "$currentCommandCondition" & ExecTasks "subConditionCheck" 0 0 1800 3600 1 $KEEP_LOGGING true true true true 1 $! - if [ $? -ne 0 ]; then + retval=$? + if [ $retval -ne 0 ]; then if [ $postPoneIfConditionFails == true ]; then Logger "Condition not met for command [$currentCommand]. Postponing command." "NOTICE" if [ $readFromFile == true ]; then @@ -1008,7 +1011,7 @@ function ExecTasks { echo "$currentCommand" >> "$mainInput" echo "$currentCommandCondition" >> "$auxInput" else - commansdArray+=($currentCommand) + commandsArray+=($currentCommand) commandsConditionArray+=($currentCommandCondition) fi mainItemCount=$((mainItemCount+1)) @@ -1033,7 +1036,9 @@ function ExecTasks { commandsArrayPid[$pid]="$currentCommand" #TODO not implemented pidsTimeArray[$pid]=$((SECONDS - seconds_begin)) - fi + else + Logger "Skipping command [$currentCommand]." "DEBUG" + fi counter=$((counter+1)) done fi @@ -1085,9 +1090,10 @@ function ExecTasks { # Return exit code if only one process was monitored, else return number of errors # As we cannot return multiple values, a global variable WAIT_FOR_TASK_COMPLETION contains all pids with their return value - if [ $noErrorLogAtAll == true ]; then - return 0 - fi + #WIP: return code has nothing to do with logging + #if [ $noErrorLogAtAll == true ]; then + # return 0 + #fi if [ $mainItemCount -eq 1 ]; then return $retval