title: grep 5 seconds of input from the serial port inside a shell-script
body: <p>I've got a device that I'm operating next to my PC and as it runs it's spitting log lines out it's serial port. I have this wired to my PC and I can see the log lines fine if I'm using either minicom or something like:</p>
  
  <pre><code>ttylog -b 115200 -d /dev/ttyS0
  </code></pre>
  
  <p>I want to write 5 seconds of the device serial output to a temp file (or assign it to a variable) and then later grep that file for keywords that will let me know how the device is operating. I've already tried redirecting the output to a file while running the command in the background, and then sleeping 5 seconds and killing the process, but the log lines never get written to my temp file. Example:</p>
  
  <pre><code>touch tempFile
  ttylog -b 115200 -d /dev/ttyS0 &gt;&gt; tempFile &amp;
  serialPID=$!
  sleep 5
  #kill ${serialPID} #does not work, gets wrong PID
  killall ttylog
  cat tempFile
  </code></pre>
  
  <p>The file gets created but never filled with any data. I can also replace the ttylog line with:</p>
  
  <pre><code>ttylog -b 115200 -d /dev/ttyS0 |tee -a tempFile &amp; 
  </code></pre>
  
  <p>In neither case do I ever see any log lines logged to stdout or the log file unless I have multiple versions of ttylog running by mistake (see commented out line, D'oh).</p>
  
  <p>I have no idea what's going on here. It seems to be a failure of redirection within my script. </p>
  
  <p>Am I on the right track? Is there a better way to sample 5 seconds of the serial port?  </p>