Shell script: Script Analysis Summary ping log file

Source: Internet
Author: User

Scripting features: For analyzing and summarizing a large number of ping log files

------------------

#!/bin/bash# check ping result# by colin# on 2016-06-08#################### #####################  function Description: This script is used to analyze and summarize a project online ping log file #path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/binlogname= ' Data/store/logs/record/ping.log ' grepkey= ' ping statistics ' WORKDIR= '/tmp/ Checkpingresult ' temppingfile= "${workdir}/temppingfile.txt" checkresult= "${workdir}/temp_check_result.txt" EMAIL= (    [email protected] e-mail address. cn) Train_ctzx= (    k1364_k817:cdyd:ctzx_42    k1364_k817:cdyd:ctzx_58     k1364_k817:cdyd:ctzx_49    k1364_k817:cdyd:ctzx_56     k1364_k817:cdyd:ctzx_55    k1364_k817:cdyd:ctzx_59     K1364_k817:cdyd:ctzx_39    k1364_k817:cdyd:ctzx_22    k1364_k817:cdyd: Ctzx_46    k1364_k817:cdyd:ctzx_36    k1364_k817:cdyd:ctzx_27    k1364_k817:hrbdx:ctzx_26    k1364_k817:hrbdx:ctzx_1     k1364_k817:cddx:ctzx_51    k1364_k817:cddx:ctzx_40     k351_k352:cdyd:ctzx_2    k351_k352:cdyd:ctzx_4    k351_k352:cdyd :ctzx_5    k351_k352:cdyd:ctzx_8    k351_k352:cdyd:ctzx_9     k351_k352:cdyd:ctzx_10    k351_k352:cdyd:ctzx_12    k351_ K352:cdyd:ctzx_13    k351_k352:cdyd:ctzx_14    k351_k352:cdyd:ctzx_15     k351_k352:cdyd:ctzx_16    k351_k352:cdyd:ctzx_17     k351_k352:cdyd:ctzx_19    k1223_k1224:hrbdx:ctzx_33    k1223_ K1224:HRBDX:CTZX_34&NBSP;&NBSP;&NBSP;&NBSP;K1223_K1224:CDDX:CTZX_41&NBSP;&NBSP;&NBSP;&NBSP;K1223_K1224:CDDX: Ctzx_47    k1223_k1224:cddx:ctzx_54    k1223_k1224:cdyd:ctzx_23    k1223 _k1224:cdyd:ctzx_38    k1223_k1224:cdyd:ctzx_45    k1223_k1224:cdyd: CTZX_48&NBSP;&NBSP;&NBSP;&NBSP;K1223_K1224:CDYD:CTZX_50&NBSP;&NBSP;&NBSP;&NBSP;K1223_K1224:CDYD:CTZX_60) SendEmail () {    temp_email_files=$1    [ $ (Wc -l ${TEMP _email_files}|awk  ' {print $1} ')  -eq 0 ] | |  {         for i in ${EMAIL[@]}         do             dos2unix -k ${temp_email_files}              mail -s  "${hostname}: ctzx check ping result"  ${i} <  ${temp_email_files}        done    }    [ -e ${temp_email_files} ]  && rm ${temp_email_files}}[ -d ${workdir} ] && rm ${ Workdir} -rf[ -f ${checkresult} ] && rm ${checkresult} mkdir  -p ${WORKDIR}/temp/ && cd ${WORKDIR} && {     for tarfile in $ (find /home/upload/ctzx/ct_tongji/ -name  ' Pinglog.tar.gz ')     do        devname=$ (echo  "${tarfile}" |awk -f/  ' {print $ (NF-1)} ')         for  T_DEV_ID in ${TRAIN_CTZX[@]}        do             train_id=$ (echo ${t_dev_id}|awk -f:   ' {print $1} ')             card_id=$ (echo ${t_dev_id}|awk -f:  ' {print  $2} ')             dev_id=$ (echo ${T_DEV_ id}|awk -f:  ' {print $3} ')              [ ${DEVNAME} = ${DEV_ID} ] && break         done        tarfilename=$ (echo  "${TARFILE}" |awk  -F/  ' {print  $NF} ')         cp ${tarfile} .         tar -zxf ${tarfilename} && rm  -f ${TARFILENAME}        ##      The    #  plus-n parameter adds the line number,-a 2 the data to be fetched, and encounters a third act empty case         #         grep -n -a 2  "${grepkey}"  ${LOGNAME}|grep -v  "${ Grepkey} "|sed -r  ' s/[^0-9\." +/ /g ' |sed  ' s/^ //g ' |grep -v  ' ^$ '  |awk  ' {$1= ' ";p rint $0} '  >  ${temppingfile}        packets_transmitted=$ (sed -n  ' p ; n '  ${TEMPPINGFILE}|awk  ' {sum+=$1} end {print sum} ')          packets_received=$ (sed -n  ' p;n '  ${TEMPPINGFILE}|awk  ' {sum+=$2} end  {print sum} ')         packet_loss=$ (sed -n  ' p;n '  ${TEMPPINGFILE}|awk  ' {sum+=$3} end {print sum/nr} ')          ping_min=$ (sed -n  ' n;p '  ${TEMPPINGFILE}|grep -vE  "([0-9]{1,3}\.) {3} " |awk  ' {print $1} '  |sort -n|uniq|sed -n  ' 1p ')         ping_avg=$ (sed -n  ' n;p '  ${TEMPPINGFILE}|grep -vE  "([0-9 ]{1,3}\.) {3} "|awk  ' {sum+=$2} end {print sum/nr} ')          ping_max=$ (sed -n  ' n;p '  ${TEMPPINGFILE}|grep -vE  "([0-9]{1,3}\.) {3} '  |awk  ' {print $3} '  |sort -n|uniq|sed -n  ' $p ')          echo  "${packets_transmitted},${packets_received},${packet_loss},${ping_min},${ Ping_avg},${ping_max} " >> ${WORKDIR}/temp/${TRAIN_ID}_a_${CARD_ID}         [ -f ${temppingfile} ] && rm ${temppingfile}     done}grouppingresult () {    checkfilename=$1     pack_sent_all=$ (awk -f,  ' {sum+=$1} end {print sum} '  ${CHECKFILENAME})     pack_receive_all=$ (awk -f,  ' {sum+=$2} end {print sum} '  ${checkfilename})     pack_ loss_avg=$ (printf %0.2f $ (awk -f,  ' {sum+=$3} end {print sum/nr} '  ${ Checkfilename}))     ping_min_avg=$ (printf %0.2f $ (awk -F,  ' {sum+=$4} &NBSP;END&NBSP;{PRINT&NBSP;SUM/NR} '  ${checkfilename}))     ping_avg_avg=$ (printf  %0.2f $ (awk -f,  ' {sum+=$5} end {print sum/nr} '  ${checkfilename})      ping_max_avg=$ (printf %0.2f $ (awk -f,  ' {sum+=$6} end {print &NBSP;SUM/NR} '  ${checkfilename})     all_result= "${pack_sent_all},${pack_receive_all} , ${pack_loss_avg},${ping_min_avg},${ping_avg_avg},${ping_max_avg} "}cd ${workdir}/temp/ &&  {    for i in $ (find . -name  "*_a_*")      do        traincard=$ (echo  $i  | awk -F/  ' {print  $NF} ')          groupPingResult ${TRAINCARD}         traincard_name=$ (echo ${traincard} | sed  ' s/_a_/,/g ')          echo  "${traincard_name},${all_result}"  >> ${checkresult}         [ -f ${traincard} ] && rm  ${traincard} -f    done    cat ${checkresult}|sort  -n -t, -k5 > ${WORKDIR}/check_result.txt    sed -i  ' 1i Train, card type, total send packet, total receive packet, loss rate, Ping_min,ping_avg,ping_max '  ${workdir}/check_result.txt    # cat ${checkresult}|sort -n -t, -k5 > ${workdir}/t_check_result.txt      #sed &NBSP;-I&NBSP; ' 1i Train, card type, total send packet, total receive packet, loss rate, Ping_min,ping_avg,ping_max '  ${workdir}/t_check_result.txt    # column -s, -t ${workdir}/t_check_result.txt > ${workdir}/check_result.txt     #[ -f ${workdir}/t_check_result.txt ] && rm ${workdir} /t_check_result.txt    [ -f ${checkresult} ] && rm $ {Checkresult}    sendemail ${workdir}/check_result.txt}

------------------

This article from "Mountain Road 18 Bend" blog, reproduced please contact the author!

Shell script: Script Analysis Summary ping log file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.