0: tid = eachLin" />
入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

Python——过滤错误日志

创建时间:2017-01-07 投稿人: 浏览次数:1104
#!/usr/bin/python

import os
import sys

file = open(sys.argv[1], "r")
for eachLine in file:
    eachLine = eachLine.strip()
    npos_id = eachLine.find("Tid")
    if npos_id > 0:
        tid = eachLine[npos_id+4 : npos_id+36]
        cmd = "fgrep -h" + tid + " /var/log/message-2017010* >> error.log"
        os.system(cmd)

功能:

   通过Tid过滤错误日志的原始语句,用于后续执行。

fgrep用法:

       -h, --no-filename
              Suppress the prefixing of file names on output.  This is the default when there is only one file (or only standard input) to search.

       -i, --ignore-case
              Ignore case distinctions in both the PATTERN and the input files.  (-i is specified by POSIX.)

-h: 不打印日志文件名

-l: 只打印文件名


阅读更多
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。