title: Bash - read log file in real time and execute command on error message
body: <p>I've been trying to read a log file in real time which sometimes contains one or more different error messages. A colleague sent me a command that, once the word "error" appears, it should update another log (a status log) with a specific number, in this case the number 2. 
  Here's the command:</p>
  
  <p><code>$(tail -n0 -f /Users/user/Desktop/file | grep error | echo 2 &gt; /Users/user/Desktop/error.log) &amp;</code></p>
  
  <p>The problem is: this command <strong><em>always</em></strong> updates error.log with the number 2, whether my file's last line was an error warning word or not. Moreover, if I try the following shorter command</p>
  
  <p><code>$ tail -n0 -f /Users/user/Desktop/file | grep error</code></p>
  
  <p>and <em>echo</em> a random word to my file, it still appears on the <em>tail</em>, so it definitely isn't filtering new lines in real time. Can you help? </p>
  
  <p>Thanks</p>