首页 > 编程语言 >python 中记录dmesg信息并进行分析的方法(@)

python 中记录dmesg信息并进行分析的方法(@)

时间:2022-11-07 15:37:29浏览次数:41  
标签:fp dmesg mesgInfo 记录 python testExample msg itmes

在Python中记录系统的dmesg 信息,并进行分析的方法简述:

 

基本命令:

  • dmesg -C 清除之前的dmesg  信息;
  • dmesg -T > testExample.msg      将dmesg 信息保存在testExample.msg中,“>” 覆盖原来的信息,“>>” 则不会覆盖原有信息,只会附加在后面;
  • dmesg -T  |  grep ata > testExample.msg,   将dmesg 中与ata相关的信息保存在testExample.msg中;

 

在Python中打开dmesg  文件,并进行分析:

方法一:

fp = open(filename, 'r')

mesgInfo = fp.readlines()

for itmes in mesgInfo:

    print(itmes)

fp.close()

 

方法二:

with open(filename, 'r') as fp:

      mesgInfo = fp.readlines()

      for itmes in mesgInfo:

             print(itmes)

标签:fp,dmesg,mesgInfo,记录,python,testExample,msg,itmes
From: https://www.cnblogs.com/FireLife-Cheng/p/16866091.html

相关文章