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

Use command

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

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

Comments