【问题标题】:How do I exit tail --follow on ERROR or FATAL log level [closed]如何退出 tail --follow on ERROR 或 FATAL 日志级别 [关闭]
【发布时间】:2020-01-26 08:23:50
【问题描述】:

tail -f 我的一项服务的日志文件,但我想在我的记录器打印任何以 OR 开头包含 ERRORFATAL 的内容后自动停止我的尾部进程

我怎样才能做到这一点?

【问题讨论】:

  • 如果您的服务进程在错误后终止,只需调用 `tail -f --pid=

标签: linux logging tail


【解决方案1】:

要在输出包含 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2019-06-06
    • 2023-04-10
    相关资源
    最近更新 更多