How to do something with Bash when a text line appears in a file

bash, grep, linux

Solution

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.

Problem

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

Original source