ketorin ketorin - 2 years ago 74
Linux Question

How to do something with bash when a text line appear to a file

I want to run a command as soon as a certain text appears in to a log file. How do I do it in bash?

Answer Source

Use command

tail -f file.log | grep --line-buffered "my pattern" | while read line
  echo $line

The --line-buffered is the key here, otherwise the read will fail.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download