ketorin ketorin - 1 year ago 38
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.