• ipmitool获取服务器sn码


    #/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 '%(key,value))
    if __name__=="__main__":
        main(ipmi_info)



  • 相关阅读:
    Linux任务前后台的切换
    如何给html元素的onclick事件传递参数即如何获取html标签的data
    关键词多空格处理
    tp3常量
    php 正则判断是否是手机号码
    thinkphp 初始化
    删除图标
    time() 在thinkphp 3.2.3 模板格式化输出
    iOS工程如何支持64-bit
    调试instruments
  • 原文地址:https://www.cnblogs.com/lieying6011/p/11943820.html
Copyright © 2020-2023  润新知