#!/bin/bashcat 1 | grep " 403 " | while read linedo index=`expr index "$line" GET` let startindex=$index+3 echo "startindex:"$startindex endindex=`expr index "$line" \?` echo "endindex:"$endindex if [ 0 -eq $endindex ]; then echo $line endindex=`expr index "$line" HTTP` echo "endindex:"$endindex let urllength=$endindex-$startindex-1 echo "urllength:"$urllength else let urllength=$endindex-$startindex-1 echo "urllength:"$urllength fi if [ $urllength -gt 0 ];then url=${line:$startindex:$urllength} echo "url:"$url url403="${url403} ${url}" fi #echo $url403done
#!/bin/bashcd /opt/logs/time=`date -d "-4 min" +%Y-%H-%M`echo $timedate=`date -d "-4 min" +'%Y-%m-%d %H:%M:%S'`echo $datefile=`ls |grep $time`echo $file#find 403 urlurl403=`cat $file | grep " 403 " | cut -d " " -f 11 --output-delimiter="\n"`#echo $url403length=`echo $url403 | wc -c`echo "length:"$lengthif [ $length -gt 500 ];then url403=${url403:0:500}fiif [ -z "$1" ]then code200=`cat $file | grep -c " 200 "` echo $code200 code403=`cat $file | grep -c " 403 "` echo $code403 code404=`cat $file | grep -c " 404 "` echo $code404 insert_sql="insert into responseCode(create_time,code200,code403,code404,url403) values(\"$date\",\"$code200\",\"$code403\",\"$code404\",\"$url403\")"else code200=`cat $file | grep "$1" | grep -c " 200 "` echo $code200 code403=`cat $file | grep "$1" | grep -c " 403 "` echo $code403 code404=`cat $file | grep "$1" | grep -c " 404 "` insert_sql="insert into responseCode(create_time,code200,code403,code404,url,url403) values(\"$date\",\"$code200\",\"$code403\",\"$code404\",\"$1\",\"$url403\")"fimysql -h 10.10.77.46 -uroot -pfanfan test -e "${insert_sql}"#rm -rf $file
#!/bin/bash#set -xcd /opt/logsadd_day=0ip_day=0add_hour=0ip_hour=0message=""DATE=`date +'%Y-%m-%d'`time=`date +'%Y-%m-%d %H:%M:%S'`path=/opt/mail/mail$DATE.logecho $pathfunction statics(){ date=`date -d "-3 min" +'%H-%M'` echo $date min=`date -d "-3 min" +'%M'` hour=`date -d "-3 min" +'%H'` echo "min="$min echo "hour="$hour files=`ls | grep "$date"` echo '[start]' addCount=`cat $files | grep 'v.jhtml' | grep -c 'add'` echo addCount=$addCount let add_day=add_day+$addCount let add_hour=add_hour+$addCount echo "add_hour="$add_hour ipCount=`cat $files| grep 'v.jhtml' | grep 'add' | cut -d ' ' -f3 | sort -u | wc -l` echo ipCount=$ipCount let ip_day=ip_day+$ipCount let ip_hour=ip_hour+$ipCount echo "ip_hour="$ip_hour ###########insert into datadabase insert_sql="insert into T_addCount(create_time,ip_count,add_count) values(\"$time\",\"$addCount\",\"$ipCount\")" mysql -h 10.10.77.46 -uroot -pfanfan test -e "${insert_sql}" if [ $min = "15" ] ; then echo "<br />---Hour Report:---">>$path echo $DATE" "<br />$date>>$path echo "<br />add count="$add_hour>>$path echo "<br />ip count="$ip_hour"<br />">>$path add_hour=0 ip_hour=0 fi if [ $date = "17-15" ] ; then echo "<br /><strong>Day Report:"</strong>$path echo "<br />"$DATE" "$date>>$path echo "<br />add counts in yesterday:"$add_day>>$path echo "<br />ip counts in yesterday:"$ip_day>>$path add_day=0 ip_day=0 #sendmail curl -F "format=html" -F "from=xiegang@sohu-inc.com" -F "to= julywang@sohu-inc.com " -F "subject=add and ip statistics" -F "body= `cat ${path}`" http://10.15.2.57/cgi-bin/alert.py fi echo '[end]'}c=1while [ $c -le 2 ]do statics sleep 1mdone