ketorin ketorin - 10 months ago 26
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?


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.