shell 脚步分析数据

来源:互联网 发布:js toggleclass 编辑:程序博客网 时间:2024/05/19 11:44

开始尝试用shell 脚步分析软件输出数据

#!/bin/sh:<<!input file  n : difference device file compare     e : same device file compare!device=$1   log_file_a=$2log_file_b=$3#convert file dos2unix $log_file_ados2unix $log_file_b#judge file if [ n == $device ] || [ e == $device ];thenif [ ! -f "$log_file_a" ];thenecho -e "no input compare file param1!\c";exit 2elseif [ ! -f "$log_file_b" ];thenecho -e "no input compare file param2!\c";exit 2fifielseecho -e "shell Usage error ! \c";exit 2fi#record last find success linelast_condition=0#multiple start time must record linemulti_line=0line=1;last_line=0;last_line_tmp=0count_num=0condition=0if [ e == $device ]thenOAR_Line=$(awk '{print NR}' $log_file_b | tail -1)cat $log_file_a | while read GAS_timedolet count_num++if (( $count_num%100 == 0 ));thenecho " handle alarm $count_num"fiGAS_time=$(echo ${GAS_time##*G:})GAS_time_s=$[GAS_time+1]#echo $GAS_timestime=0;etime=0;GAS_time_e=0if [ 1 == condition ];thenline='expr $line - 1'if [ 0 -ne multi_line ];thenline='expr $last_line - $multi_line'multi_line=0fielseline=1ficondition=0while [ $line -le $OAR_Line ]doif [ 1 == line ]thenstime=$(awk 'NR=='$line' {print $0}' $log_file_b)#stime=$(sed -n ''$line'p' $log_file_b)elsewhile [ $line -ge 3 ]dostime=$(sed -n ''$line'p' $log_file_b)if [[ "$stime" =~ "S=" ]]thenlet last_line_tmp=line-1etime_tmp=$(sed -n ''$last_line_tmp'p' $log_file_b)if [[ "$etime_tmp" =~ "E=" ]]thenbreakelselet line--continuefielselet line--continuefidonefistime=$(echo ${stime##*S=})[ ! $stime = ~^[0-9] ] || echo -e "GAS_time:$GAS_time    GAS_time_s:$GAS_time_s     stime:$stime \c"let line++etime=$(sed -n ''$line'p' $log_file_b)while [ $line -le $OAR_Line ];doif [[ "$etime" =~ "E=" ]]then#echo $etimebreakelselet multi_line++let line++etime=$(sed -n ''$line'p' $log_file_b)fidoneetime=$(echo ${etime##*E=})#GAS_time=$[GAS_time+1]let GAS_time_e=GAS_time+8#echo "GAS_time_e:$GAS_time_e     stime:$stime     etime:$etime "#if [ 1488870848 = $GAS_time ];then#echo "GAS_time:$GAS_time    GAS_time_s:$GAS_time_s    GAS_time_e:$GAS_time_e   stime:$stime     etime:$etime "#fi[ ! $etime = ~^[0-9] ] || echo -e "GAS_time:$GAS_time    GAS_time_s:$GAS_time_s    GAS_time_e:$GAS_time_e   stime:$stime     etime:$etime \c"if [ $GAS_time_s -ge $stime ];thenif [ $GAS_time_e -lt $etime ];thencondition=1last_line=$linebreakfifilet line++doneif [ 0 -eq $condition ];thenecho -e " ***   error   ***: \c";echo "GAS_time:$GAS_time GAS_time_e:$GAS_time_e   stime:$stime     etime:$etime "fidoneelif [ n == $device ]thenline_num_b=$(awk '{print NR}' $log_file_b | tail -1)cat $log_file_a | while read time_adobequal=0;line_b=1old_time_a=$time_anew_time_a=$(echo ${time_a##*G:})while [ $line_b -le $line_num_b ];dotime_b=$(sed -n ''$line_b'p' $log_file_b)time_b=$(echo ${time_b##*G:})if [ $new_time_a -eq $time_b ];thenbequal=1break;filine_b=`expr $line_b + 1`doneif [ 0 -eq $bequal ];thenecho " error    in another file no find : $old_time_a"fidoneelseecho -e "shell fisrt praram error ! \c";exit 2fi

备注

0 0
原创粉丝点击