0

so far I have this:

for each in {01..10} ; do ./sb0$each/tomcat_sb0$each start;done

that will start my apps at once, but I want it to wait until it reads one line in a file, what's the easiest way to do that?

Anthony
  • 5
  • 1
  • 3

1 Answers1

1
while ! grep "the line you're searching for" /path/to/the.file
do sleep 10; done
for each in {01..10} ; do ./sb0$each/tomcat_sb0$each start;done

This solution has a while loop that will continue as long as the line you're searching for isn't found in the file. The loop contains just a sleep of 10 seconds, so that it will check every ten seconds for the line you want. Obviously you could set this to whatever you want.

The grep searches for a pattern in a given file, and returns false if nothing matches the pattern. The ! means not, and as not false = true, the loop continues as long as the grep command returns false.

For example, if you're looking for the line start the apps now chuck in file /var/tmp/foo.txt it would look like

 while ! grep "start the apps now chuck" /var/tmp/foo.txt;

If the line exists the answer won't have zero length so the conditional will return false and the loop will exit.

stib
  • 4,389