0
I typed a script to check some configurations in Linux servers from a list. There are too many servers in list, so I divided 10 by 10 this list with below loop:
...
...
for ((i=0; i <= $serverCounter; i+=15))
do
if [ $i -ge $serverCounter ]
then
exit
else
echo $i
Kontrol $list &
((first+=15))
((last+=15))
fi
done
...
...
But at this situation I cannot exit from this loop. You can see I added an if condition to exit but it doesn't work (I don't know why).
How can I exit this loop without abandon from "&" that at EOL (Kontrol function line)
5Your test
$i -ge $serverCounter
is redundant with the one in the for loop (only catches the case where$i -eq $serverCounter
). As written your code will still start N parallel instances ofKontrol
where N isserverCounter/15
, so your problem could be that all these instances eventually overload your system and you haven't got enough CPU left to continue the loop. You may have to write something more complex to never have more that K instances of Kontrol running at the same time. – xenoid – 2018-05-11T12:15:21.5271Your loop will run a finite amount of times as it is. I will never be greater then serverCounter, because it will exist when it is equal or greater to serverCounter as it is. – Ramhound – 2018-05-11T12:25:36.540
actually there is no problem about running and finishing. I cannot see the process in ps -ef, so script can finish but I cannot fall into bash screen after last control. just the cursor is blinking. The problem is on "&" redirection I think so. – Gefolge – 2018-05-11T12:54:01.230
yes @Ramhound I know that but I added that line after this problem already. So yes I cannot enter true if statement but I was couldn't exit the loop before if condition anyway. – Gefolge – 2018-05-11T13:14:53.327
@Gefolge - Your exit condition is only evaluated once per iteration of the loop unless you have an additional conditional which breaks or continues the loop. – Ramhound – 2018-05-11T16:23:35.213
there wasn't an if condition at the first script. I added it to avoid to infinite loop. – Gefolge – 2018-05-11T17:49:28.320