title: Not receiving the email of grep output after bash command is run
body: <p>I have the code below, it does not send the grep output to email but it shows the output command line. Not sure what I'm doing wrong</p>
  
  <pre><code>sudo tail -f  /path/to/file | while read line ; do 
      egrep 'successfully started \[[0-9] out of [0-9]\] components|successfully started \[[0-9] out of [0-9]\] components' 
      if [ $? -eq 0 ]; then
          (echo " RESTARTS"; echo; echo $line) | mail -s "RESTART" email@email.com
      else
          echo " FAILS"
      fi
  done
  </code></pre>
  
  <p>[UPDATE]</p>
  
  <p>There is another way I was trying to do this but it wont send email..I was just making sure that I can break out of loop and not go forever and so thats why I put the tail in while</p>
  
  <pre><code>while read line; do
  
      echo "$line" | sudo tail -f  /opt/bmc/ao/cdp/tomcat/logs/grid.log
  
      if [ $(echo "$line" | grep -E 'successfully started \[[0-9] out of [0-9]\] components|successfully started \[[0-9] out of [0-9]\] components' | wc -l) -ne 0 ]; then
          (echo "CDP RESTARTS"; echo; echo "$line") | mail -s "BAOCDP AUTO RESTART" noreply@google.com
  
          break
      fi
  
  done 
  </code></pre>