title: Loop shell script until successful log message
body: <p>I am trying to get a shell script to recognize when an app instance has come up.  That way it can continue issuing commands.</p>
  
  <p>I've been thinking it would be something like this:</p>
  
  <pre><code>#/bin/bash
  
  startApp.sh
  
  while [ `tail -f server.log` -ne 'regex line indicating success' ]
  do
  
  sleep 5
  
  done
  
  echo "App up"
  </code></pre>
  
  <p>But, even if this worked, it wouldn't address some concerns:</p>
  
  <ul>
  <li>What if the app doesn't come up, how long will it wait </li>
  <li>What if there is an error when bringing the app up</li>
  <li>How can I capture the log line and echo it</li>
  </ul>
  
  <p>Am I close, or is there a better way?  I imagine this is something that other admins have had to overcome.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I found this on super user</p>
  
  <p><a href="https://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found">https://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found</a></p>
  
  <pre><code>tail -f logfile.log | while read LOGLINE
  do
     [[ "${LOGLINE}" == *"Server Started"* ]] &amp;&amp; pkill -P $$ tail
  done
  </code></pre>
  
  <p>My only problem with this is that it might never exit.  Is there a way to add in a maximum time?</p>