小编Wen*_*ong的帖子

How to get “instant" output of “tail -f” as input?

I want to monitor a log file, when a new log message match my defined pattern (say contain “error”), then send out an email to me.

To do that, I wrote a python script monitor.py, the main part looks like:

import sys

for line in sys.stdin:
    if "error" in line:
        print line 
Run Code Online (Sandbox Code Playgroud)

It works well when I use tail my.log | python monitor.py, then I switch to tail -f my.log | python monitor.py, then it doesn’t work, at …

linux bash tail

3
推荐指数
1
解决办法
1251
查看次数

标签 统计

bash ×1

linux ×1

tail ×1