请教一个subprocess.Popen,执行tail -f xxx.log|grep "error"的问题

0
我的目的是想监控 /var/log/message中的error关键字,但是发现用tail -f |grep这种不起作用,打印不出来带有error的行。请大侠帮忙看看。


logname= '111.log'
command='tail -f '+logname+'|grep "error"'
popen=subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
while True:
    line=popen.stdout.readline().strip()
    print line
已邀请:
0

牟瑞 - 大数据 Hadoop 讲师 Hadoop入门课程地址:http://www.hellobi.com/course/39 有架构师,技术总监,CTO的职位请联系我! 2016-07-26 回答

grep "error" 111.log >> error.log
你直接用上面的shell脚本不可以么?都输出到error.log文件里面了。

要回复问题请先登录注册