I am trying to implement a script that wait for a specific message in a log file. Once the message is logged then I want to continue the script.
Here’s what I am trying out with tail -f and grep -q:
# tail -f logfile | grep -q 'Message to continue'
The grep never quit and so it waits forever even if ‘Message to continue’ is logged in the file.
When I run this without -f it seems to work fine.
tail -fwill read a file and display lines later added, it will not terminate (unless a signal likeSIGTERMis sent).grepis not the blocking part here,tail -fis.grepwill read from the pipe until it is closed, but it never is becausetail -fdoes not quit and keep the pipe open.A solution to your problem would probably be (not tested and very likely to perform badly):