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

在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)

posted @   咸鱼书生  阅读(242)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示