BASH: Wait for log entry

For a startup script, I needed to start JBoss and start another component as soon as the complete JBoss server was started. When you execute the “” script that comes with JBoss, it immediately exits and starts JBoss in the background (which is quite nice I think). Unfortunately, when I started the other component using this method, the additional program was unhappy, since JBoss was not ready yet. So I had to come up with a trick to delay the start of the additional program.

So with the help of the internet and my co-worker, we came up with the following script:

while read LINE; do
    if [[ $LINE =~ JBoss\ \\\(MX\ MicroKernel\\\).*Started\ in ]]; then
        echo "JBoss started!"
done < <(tail -f $LOGFILE)
# Do something here

Basically, you start the JBoss server by invoking the script that comes with the JBoss package. Then, we use tail -f with a while-loop to look at every line. Using a regular expression, we wait for the "JBoss [..] Started in [..]" log entry and use break to get out of the while-loop. The script then continues like normal.