Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best answer I can come up with is this</p> <ol> <li>Put a timeout on the read, <code>tail -f logfile | read -t 30 line</code></li> <li>Start tail with <code>--pid=$$</code>, that way it'll exit when the bash-process has finished.</li> </ol> <p>It'll cover all cases I can think of (server hangs with no output, server exits, server starts correctly).</p> <p>Dont forget to start your tail before the server.</p> <pre><code>tail -n0 -F logfile 2&gt;/dev/null | while read -t 30 line </code></pre> <p>the <code>-F</code> will 'read' the file even if it doesn't exist (start reading it when it appears). The <code>-n0</code> won't read anything already in the file, so you can keep appending to the logfile instead of overwriting it each time, and to standard log rotation on it.</p> <p><b>EDIT:</b><br> Ok, so a rather crude 'solution', if you're using tail. There are probably better solutions using something else but tail, but I got to give it to you, tail gets you out of the broken-pipe quite nicely. A 'tee' which is able to handle SIGPIPE would probably work better. The java process actively doing a file system drop with an 'im alive' message of some sort is probably even easier to wait for.</p> <pre><code>function startServer() { touch logfile # 30 second timeout. sleep 30 &amp; timerPid=$! tail -n0 -F --pid=$timerPid logfile | while read line do if echo $line | grep -q 'Started'; then echo 'Server Started' # stop the timer.. kill $timerPid fi done &amp; startJavaprocess &gt; logfile &amp; # wait for the timer to expire (or be killed) wait %sleep } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload