A sample of how you would do what you want in perl.
#!/usr/bin/perl
use strict;
use warnings;
# Start the first script
my $first_script = `/script1.sh`;
my $string_to_find = 'Server Blah Blah started';
my $string_not_found = 1;
my $counter = 0; # counter ofcourse start at 0
my $timer = 300; # since your sleep is set for 1 second this will
# count to 300 before exiting
while($string_not_found){
exit if ($counter > $timer); # this will make the application exit
# if the give timer is hit
# you can aswell replace it by
# $string_not_found = 0 if...
# if you want it to run the 2nd code
# as an attempt instead of only exiting
my $last_line = `tail -1 /my/app/log/file.out`;
if($last_line =~ /$string_to_find/ig) {
$string_not_found = 0;
}else {
# sleep a little
$counter++;
sleep 1;
}
}
# By the time we are here we are good to go with the next script.
my $second_script = `/script2.sh`;
print 'Finished';
exit;
With the above code it will only run the second program if the word was found once the first program finish printing it is output.
UPDATE:
If the program does not output what you want but there is a log file where it will write the info you need, you can use it within perl aswell so your not limited at all.