大牛牛 2014-05-27
代码如下:
#!/bin/bash
#purpose:count nginx or apache or other webserver status code using jiankongbao
#how to:run the script every 5 minutes with crontab
log_path="/var/log/nginx/www.jb51.net/access.log"
becur=`date -d "5 minute ago" +%H%M%S`
code=(`tac $log_path | awk -v a="$becur" -v total=0 -F [' ':] '{
t=$5$6$7
if (t>=a){
code[$12]++
total++
}
else {
exit;
}
}END{
print code[404]?code[404]:0,code[500]?code[500]:0,total
}'
`)
c404=${code[0]}
c500=${code[1]}
total=${code[2]}
echo -e "<pre>\nc404:${c404}\nc500:${c500}\ntotal:${total}\n</pre>" > /data/www/status/www.jb51.net.html代码如下:
<pre> c404:1102 c500:545 total:55463 </pre>