开始尝试用shell 脚步分析软件输出数据
#!/bin/sh
:<<!
input file n : difference device file compare
e : same device file compare
!
device=$1
log_file_a=$2
log_file_b=$3
#convert file
dos2unix $log_file_a
dos2unix $log_file_b
#judge file
if [ n == $device ] || [ e == $device ];then
if [ ! -f "$log_file_a" ];then
echo -e "no input compare file param1!\c";exit 2
else
if [ ! -f "$log_file_b" ];then
echo -e "no input compare file param2!\c";exit 2
fi
fi
else
echo -e "shell Usage error ! \c";exit 2
fi
#record last find success line
last_condition=0
#multiple start time must record line
multi_line=0
line=1;last_line=0;last_line_tmp=0
count_num=0
condition=0
if [ e == $device ]
then
OAR_Line=$(awk '{print NR}' $log_file_b | tail -1)
cat $log_file_a | while read GAS_time
do
let count_num++
if (( $count_num%100 == 0 ));then
echo " handle alarm $count_num"
fi
GAS_time=$(echo ${GAS_time##*G:})
GAS_time_s=$[GAS_time+1]
#echo $GAS_time
stime=0;etime=0;GAS_time_e=0
if [ 1 == condition ];then
line='expr $line - 1'
if [ 0 -ne multi_line ];then
line='expr $last_line - $multi_line'
multi_line=0
fi
else
line=1
fi
condition=0
while [ $line -le $OAR_Line ]
do
if [ 1 == line ]
then
stime=$(awk 'NR=='$line' {print $0}' $log_file_b)
#stime=$(sed -n ''$line'p' $log_file_b)
else
while [ $line -ge 3 ]
do
stime=$(sed -n ''$line'p' $log_file_b)
if [[ "$stime" =~ "S=" ]]
then
let last_line_tmp=line-1
etime_tmp=$(sed -n ''$last_line_tmp'p' $log_file_b)
if [[ "$etime_tmp" =~ "E=" ]]
then
break
else
let line--
continue
fi
else
let line--
continue
fi
done
fi
stime=$(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 ];do
if [[ "$etime" =~ "E=" ]]
then
#echo $etime
break
else
let multi_line++
let line++
etime=$(sed -n ''$line'p' $log_file_b)
fi
done
etime=$(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 ];then
if [ $GAS_time_e -lt $etime ];then
condition=1
last_line=$line
break
fi
fi
let line++
done
if [ 0 -eq $condition ];then
echo -e " *** error ***: \c";echo "GAS_time:$GAS_time GAS_time_e:$GAS_time_e stime:$stime etime:$etime "
fi
done
elif [ n == $device ]
then
line_num_b=$(awk '{print NR}' $log_file_b | tail -1)
cat $log_file_a | while read time_a
do
bequal=0;line_b=1
old_time_a=$time_a
new_time_a=$(echo ${time_a##*G:})
while [ $line_b -le $line_num_b ];do
time_b=$(sed -n ''$line_b'p' $log_file_b)
time_b=$(echo ${time_b##*G:})
if [ $new_time_a -eq $time_b ];then
bequal=1
break;
fi
line_b=`expr $line_b + 1`
done
if [ 0 -eq $bequal ];then
echo " error in another file no find : $old_time_a"
fi
done
else
echo -e "shell fisrt praram error ! \c";exit 2
fi
备注