0

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"
done

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

deostroll
  • 297
  • 1
  • 4
  • 9
  • 1
    Does this answer your question? [Bash tail -f with while-read and pipe hangs](https://unix.stackexchange.com/questions/309453/bash-tail-f-with-while-read-and-pipe-hangs); actually you need `--line-buffered` for the `grep` commnad. – αғsнιη Apr 08 '21 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 08 '21 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 08 '21 at 13:17
  • that's a different question and you can find your answer here as better alternative for what currently you are doing https://unix.stackexchange.com/q/45941/72456 – αғsнιη Apr 08 '21 at 15:07

0 Answers0