#!/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: 只打印文件名