I tail -f
the log file of one of my services, but I would like to automatically stop my tail process once my logger has printed any content starting with OR containing ERROR or FATAL.
How can I achieve this?
To terminate tail -f
immediately after the output has a line containing ERROR or FATAL, try:
tail -f file.log | awk '{print} /ERROR|FATAL/{exit}'
$ cat file.log
abc
def
ghi
ERROR
jkl
mno
pqr
$ tail -f file.log | awk '{print} /ERROR|FATAL/{exit}'
abc
def
ghi
ERROR