I am trying to tail a log file. At some point the program writing to the log file will say "your foo is ready". I expect my tail -f to conclude gracefully. So I came up with the following lines of code:

tail -f out.log | grep ready | while read ln; do
  echo "ln: $ln"

I stopped my coding prematurely since I cannot understand why I don't see any output.

  • 1
    Does this answer your question? Bash tail -f with while-read and pipe hangs; actually you need --line-buffered for the grep commnad. Apr 8, 2021 at 12:26
  • 1
    hi @deostroll - that code will never terminate.. If you just run the tail and grep do you see the "your foo is ready" - if not there's the problem. Then if you add the --line-buffered it will loop and wait for the next "your foo is ready"
    – Mr R
    Apr 8, 2021 at 12:27
  • But how to terminate the whie-read once I have asserted the existence of that particular line in the log file, and, have bash continue with the next statement?
    – deostroll
    Apr 8, 2021 at 13:17
  • that's a different question and you can find your answer here as better alternative for what currently you are doing unix.stackexchange.com/q/45941/72456 Apr 8, 2021 at 15:07


Browse other questions tagged or ask your own question.