python+linux常用分析log方法

本文讲述了,利用python 及linux的常用命令来快速对系统业务处理的log摘取,快速分析问题及定位问题

        esl_update=os.popen('cat eslw*.log|grep %s '%esl_id).read()
        print ("价签%s更新过程如下" %esl_id + "\n"+ esl_update)
        print("===============================================")
        print("价签更新的详细情况筛检")
        receive_time=os.popen('cat eslw*.log|grep %s |grep receive|grep UPDATE|cut -d" " -f1,2' %esl_id ).read()
        print("价签接收任务时间为:" + "\n"+ receive_time)
        session_create_time=os.popen('cat eslw*.log|grep %s |grep session_created|grep UPDATE|cut -d, -f6,9' %esl_id ).read()
        session_create_time=os.popen('cat eslw*.log|grep %s |grep session_created|grep UPDATE|cut -d, -f7,10' %esl_id ).read()
        print("价签数据打包时间为:" + "\n"+ session_create_time)
        ack_status_update=os.popen('cat eslw*.log|grep %s |grep ack_status|grep UPDATE|cut -d, -f4,12,14' %esl_id ).read()
        print("价签update_ack信息为:" + "\n"+ ack_status_update)
        ack_status_QUERY=os.popen('cat eslw*.log|grep %s |grep ack_status|grep QUERY|cut -d, -f4,12,,14' %esl_id ).read()
        print("价签query_ack信息为:" + "\n"+ ack_status_QUERY)
        set_channel=os.popen('cat eslw*.log|grep %s |grep action=signin|cut -d, -f8|uniq|cut -d"=" -f2' %esl_id ).read().strip()
        print("价签通讯setchannle及所选通讯ap信息:" + "\n"+ set_channel)
        set_ap=os.popen('cat eslw*.log|grep %s|grep ack_status|cut -d, -f4,5|sort|uniq' %esl_id ).read()
        print(set_ap)
        set_channel_toAp=os.popen('cat eslw*.log |grep %s|grep heatp_data|cut -d, -f4,5,7|sort|uniq -c' %set_channel).read()
        print("价签分组信道在如下AP下通讯:"+ "\n"+ set_channel_toAp)
        rf_power=os.popen('cat eslw*.log|grep %s|grep ack_status |cut -d, -f15|sort|uniq -c' %esl_id ).read()
        print("价签通讯过程能量值变化:" + "\n"+ rf_power)
        AP_change=os.popen('cat eslw*.log|grep %s |grep frame_retry |cut -d, -f7|sort|uniq -c' %esl_id ).read()
        print("价签通讯单AP重试统计:" + "\n"+ AP_change)
        AP_change_payload=os.popen('cat eslw*.log|grep %s |grep action=payload_retry |cut -d, -f6|sort|uniq -c' %esl_id ).read()
        print("价签通讯单AP重试统计:" + "\n"+ AP_change_payload)
        count_retry=os.popen('cat eslw*.log|grep %s |grep action=esl_update_finished |cut -d, -f5,6|uniq -c' %esl_id ).read()
        print("价签通讯结果统计:" + "\n"+ count_retry)
        update_time=os.popen('cat eslw*.log|grep %s |grep ack_result |cut -d, -f12|sort|uniq -c' %esl_id ).read()
        print("价签每次更新用时:" + "\n"+ update_time)
        print("价签漫游状态。。。")
        moaming_ap=os.popen('cat eslw*.log |grep %s|grep bind_ap |cut -d, -f2|cut -d"=" -f2 |sort|uniq' %esl_id).read().strip()
        banding_ap=os.popen('cat eslw*.log |grep %s|grep %s |cut -d, -f5|cut -d"=" -f2 |sort|uniq' %(esl_id,moaming_ap)).read().strip()
        ap_id=os.popen('cat eslw*.log |grep %s|grep %s |grep ack_status|cut -d, -f5|sort|uniq' %(esl_id,banding_ap)).read().strip()
        if moaming_ap=="roaming_timeout":
           print("价签绑定漫游新ap超时,漫游失败!!")
        elif moaming_ap=="enter_roaming":
           moaming_to_ap=os.popen('cat eslw*.log |grep %s |grep %s|cut -d"," -f6|cut -d"=" -f2 |sort|uniq' %(esl_id,moaming_ap)).read()
           print("价签选择新AP开始漫游到ap为: %s,mac为: %s" %(ap_id,moaming_to_ap))
        elif moaming_ap=="roaming_finish":
           roamsuceess=os.popen('cat eslw*.log|grep %s|grep %s|cut -d"," -f5 |cut -d"=" -f2 |sort|uniq' %(esl_id,moaming_ap)).read()
           print("价签以绑定漫游apid为:%s,mac为: %s" %(ap_id,roamsuceess))
        else:
           print("价签无需或者无漫游 AP!!")
        print("====================================================")

你可能感兴趣的:(Python学习笔记记录)