dmidecode收集系统信息
[root@133 systeminformation]# vim dmidecode_1.py #!/usr/bin/env python from subprocess import Popen,PIPE p = Popen([‘dmidecode‘],stdout=PIPE) data=p.stdout line_s = [] #定义一个空列表 dmi = {} #定义一个空字典 a = True #设置标志位 a = True while a: line = data.readline() if line.startswith(‘System Information‘): #判断以System Information开头的段, while True: line = data.readline() if line == ‘\n‘: #取该段落,直到有空行 a = False break else: line_s.append(line) dmi_dic = dict([i.strip().split(‘:‘) for i in line_s]) #把空格和换行符删除 dmi[‘Manufacturer‘] = dmi_dic[‘Manufacturer‘].strip() #打印key= Manufacturer的键值对 print dmi print {‘\n‘*20} for k,v in dmi_dic.items(): #打印以System Information开头的段,以key、value打印出来 dmi[k] = v.strip() print dmi [root@133 systeminformation]# python dmidecode_1.py {‘Manufacturer‘: ‘Dell Inc.‘} set([‘\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n‘]) {‘SKU Number‘: ‘Not Specified‘, ‘UUID‘: ‘4C4C4544-0048-4210-8044-B4C04F543258‘, ‘Family‘: ‘Not Specified‘, ‘Serial Number‘: ‘4HBDT2X‘, ‘Version‘: ‘Not Specified‘, ‘Product Name‘: ‘PowerEdge R710‘, ‘Wake-up Type‘: ‘Power Switch‘, ‘Manufacturer‘: ‘Dell Inc.‘}
注意:在Python里,以下这些对象相当于布尔值的False
空列表([] )
空元组(() )
空字典({} )
空字符串(‘‘ )
零值(0 )
特殊对象None
对象False
本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1884514
原文地址:http://daixuan.blog.51cto.com/5426657/1884514