python+linux常用分析log方法


本文はpythonとlinuxの常用コマンドを利用してシステム業務処理のlog抽出を迅速に行い、問題と位置決め問題を迅速に分析することを述べた.
        esl_update=os.popen('cat eslw*.log|grep %s '%esl_id).read()
        print ("  %s      " %esl_id + "
"
+ 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(" :" + "
"
+ 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(" :" + "
"
+ 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 :" + "
"
+ 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 :" + "
"
+ 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 :" + "
"
+ 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 :"+ "
"
+ 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(" :" + "
"
+ 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 :" + "
"
+ 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 :" + "
"
+ 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(" :" + "
"
+ count_retry) update_time=os.popen('cat eslw*.log|grep %s |grep ack_result |cut -d, -f12|sort|uniq -c' %esl_id ).read() print(" :" + "
"
+ 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("====================================================")