我正在尝试从客户端服务器收集错误报告,并将其存储在主服务器中。如果报告了错误,则会在主服务器的output.error文件中对其进行更新。因此,如何在此文件中搜索以下行。 如果存在这些行,那么我将执行某些任务。 错误示例:-
3C81E43F 0203220415 P U topsvcs Late in sending heartbeat
4B436A3D 0318052119 T H fscsi1 LINK ERROR
BFE4C025 0302224219 P H sysplanar0 UNDETERMINED ERROR
实际output.error文件
---------------------------------------------------------------------
Errpt report for 192.168.1.52
3C81E43F 0203220415 P U topsvcs Late in sending heartbeat
---------------------------------------------------------------------
Errpt report for 192.168.1.85
DCB47997 0318052119 T H hdisk11 DISK OPERATION ERROR
4B436A3D 0318052119 T H fscsi1 LINK ERROR
---------------------------------------------------------------------
Errpt report for 192.168.5.62
BFE4C025 0302224219 P H sysplanar0 UNDETERMINED ERROR
---------------------------------------------------------------------
Errpt report for 192.168.7.89
---------------------------------------------------------------------
Errpt report for 192.168.5.87
答案 0 :(得分:-1)
听起来像是典型的正则表达式场景:
with open('logfile.log', 'r') as f:
for line in f:
if re.match('___your_regex___', line):
do_something(line)