hey everyone,
I'm having some trouble breaking down some code. It's simple a control script that takes machines meant to be backed up from a list. Then according to that will run multi-threaded processes up until the specified thread limit.
for example if there are 4 machines to be backed up, and you specify the --threads=3 if will do the first 3, wait for one to finish before running the 4th.
Here's my problem. I know what this code does, but not how it works. Any help in breaking this down would be greatly appreciated!
concurrent=`echo $1 | sed -e 's/--threads=//'`
maxprocs=`cat $serverset | wc -l`
tick=2
for ((i=0; i<$concurrent; i+=1 )); do running[$i]=123456789; done
ran=0
until
while [ $ran -lt $maxprocs ]; do
for ((p=0; p<$concurrent; p+=1 )); do
proc=${running[$p]}
ps -p $proc | fgrep $proc >/dev/null
if [ $? -ne '0' ] ; then
runproc $ran &
running[$p]=$!
((ran+=1))
if [ $ran -ge $maxprocs ]; then break 1; fi
fi
done
sleep $tick
done
sleep $tick
do [ `jobs -r|wc -l` -eq 0 ]
done
wait