#/bin/python3
import sys,os,time,subprocess
#sys.argv[1] 为ipmi 文件 内容格式为: ipmi_host ipmi_user ipmi_passwd
ipmi_info=sys.argv[1]
def get_sn(ipmi_host,ipmi_user,ipmi_passwd):
# result = os.system(" echo '%s' $(ipmitool -I lanplus -H '%s' -U '%s' -P '%s' fru list|grep 'Product Serial'|head -n 1|awk -F '[: ]+' '{print $4}')"%(ipmi_host,ipmi_host,ipmi_user,ipmi_passwd))
result = subprocess.getoutput("ipmitool -I lanplus -H '%s' -U '%s' -P '%s' fru list|grep 'Product Serial'|head -n 1|awk -F '[: ]+' '{print $4}'"%(ipmi_host,ipmi_user,ipmi_passwd))
print(result)
return result
def main(ipmi_info):
with open(ipmi_info, 'r',encoding='utf-8') as f:
lines = f.readlines()
sn_dict={}
for line in lines:
info=line.split( )
sn_info=get_sn(info[0],info[1],info[2])
sn_dict[info[0]]=sn_info
nowtime=time.strftime('%Y-%m-%d-%H:%M:%S')
with open('%s.txt'%(nowtime),'w',encoding='utf-8') as f1:
for key,value in sn_dict.items():
f1.write('%s %s\r\n'%(key,value))
if __name__=="__main__":
main(ipmi_info)