In have a function which I call in a loop in parallel:
#!/bin/bash
my_func()
{
until [[ $entity status is OK ]]; do
sleep 5
echo "count=$count"
if (( timeout_flag == 1 )); then
break
fi
done
}
_arr=(e1 e2 e3)
count=0
timeout=60
timeout_flag=0
for entity in "${_arr[@]}"; do
my_func "${entity}" &
done
while [[ "${count}" -lt "${timeout}" ]]; do
sleep 5
count=count+5
done
timeout_flag=1
echo "Timeout reached"
sleep 1
I want all functions to periodically check until the status of an entity is OK and wait for all OK statuses or stop all the (remaining) functions when timeout is reached? Whatever comes first. The above does not seem to work and I need to kill it manually.
Why am I getting
"Timeout reached"
echoed at the end and the script is not waiting for functions to finish?Why
count=0
in my_func and is not increasing?