分析linux日志的烂脚本,记录下来

shell脚本可真难写啊,没办法,憋了两小时写了个烂脚本,用来统计我的日志文件中的各种超时数据

 

#!/bin/sh
if [ "$1" = "" ]
 then echo "文件未指定!"
 exit 1
else
 if [ ! -f $1 ]
  then echo "文件$1不存在!"
  exit 1
 fi
fi

temp="$1"
fd=${temp##*.}
if [ "$fd" = "proxy" -o "$fd" = "log" ]
 then fd=`date +%Y-%m-%d`
fi

all=`grep -c DefaultWebInterceptor $1`
products=`grep -c "getProductInfosByIds - \[用时:[1-9]," $1`
images=`grep -c "fillImageInfo - \[用时:[1-9]," $1`
comments=`grep -c "fillCommentInfo - \[用时:[1-9]," $1`
tsearch=`grep -c "sendSearchMessage - \[用时:[1-9]," $1`
echo "------------------汇总时间:$fd"
echo "总超时数:$all"
echo "商品数据超时:$products"
echo "图片数据超时:$images"
echo "评论数据超时:$comments"
echo "merge数据超时:$tsearch"

for i in {0..23}
do
starthour=$i
endhour=`expr $i + 1`
if [ $starthour -lt 10 ]
 then starthour="0$starthour"
fi
if [ $endhour -lt 10 ]
 then endhour="0$endhour"
fi
starttime="$fd $starthour"
endtime="$fd $endhour"
products=`sed -n -e "/$starttime/,/$endtime/p" $1 | grep -c "getProductInfosByIds - \[用时:[1-9],"`
images=`sed -n -e "/$starttime/,/$endtime/p" $1 | grep -c "fillImageInfo - \[用时:[1-9],"`
comments=`sed -n -e "/$starttime/,/$endtime/p" $1 | grep -c "fillCommentInfo - \[用时:[1-9],"`
tsearch=`sed -n -e "/$starttime/,/$endtime/p" $1 | grep -c "sendSearchMessage - \[用时:[1-9],"`
echo "------------------分时时间:$starttime"
echo "商品数据超时:$products"
echo "图片数据超时:$images"
echo "评论数据超时:$comments"
echo "请求merge超时:$tsearch"
done
exit 0

你可能感兴趣的:(linux)