如何退出 tail --follow on ERROR 或 FATAL 日志级别

How do I exit tail --follow on ERROR or FATAL log level

tail -f 我的一项服务的日志文件,但我想在我的记录器打印任何以 OR 开头且包含 ERROR[=17 的内容后自动停止尾进程=] 或 致命的.

我怎样才能做到这一点?

要在输出包含 ERROR 或 FATAL 的行后立即终止 tail -f,请尝试:

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