摘要:为了方便查看多个网站日志的百度蜘蛛情况,所以闲的蛋疼弄个echarts,使用shell编程,获取cat结果通过 curl post到数据库里进行统计。每天定时执行。...
为了方便查看多个网站日志的百度蜘蛛情况,所以闲的蛋疼弄个echarts,使用shell编程,获取cat结果通过 curl post到数据库里进行统计。每天23:59定时执行。严格来说应该每天的0点 以后统计前一天的,但是日志每个月1号0点自动切割,这样 切割以后 没办法统计到上个月最后一天的数据。所以就提前一分钟统计当天数据。
//昨天日志整理 #!/bin/bash site='baoge' dd=$(date +%d/%B) num1=$(cat /www/wwwlogs/baoge.net.log | grep ${dd} |grep www.baidu.com/sear -c) num2=$(cat /www/wwwlogs/m.baoge.net.log | grep ${dd} |grep www.baidu.com/sear -c) days=$(date +"%Y-%m-%d") curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num1'","type":1,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num2'","type":2,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add
历史日志数据统计方法
#!/bin/bash site='baoge' for a in {1..9} do if [ $a -lt 10 ] then dd='0'$a'/May' days='2021-05-0'$a else dd=$a'/May' days='2021-05-'$a fi num1=$(cat /www/wwwlogs/baoge.net.log | grep ${dd} |grep www.baidu.com/sear -c) num2=$(cat /www/wwwlogs/m.baoge.net.log | grep ${dd} |grep www.baidu.com/sear -c) curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num1'","type":1,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num2'","type":2,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add done
已压缩分割的历史日志统计方法
#!/bin/bash site='baoge' for a in {1..28} do if [ $a -lt 10 ] then dd='0'$a'/Feb' days='2021-03-0'$a else dd=$a'/Feb' days='2021-03-'$a fi num1=$(gzip -dc /www/wwwlogs/baoge.net.log_2021-03-01_000002.log.gz | grep ${dd} |grep www.baidu.com/sear -c) num2=$(gzip -dc /www/wwwlogs/m.baoge.net.log_2021-03-01_000015.log.gz | grep ${dd} |grep www.baidu.com/sear -c) curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num1'","type":1,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add curl -i -X POST -H 'Content-type':'application/json' -d '{"num":"'$num2'","type":2,"site":"'$site'","days":"'$days'"}' http://aaaa.hezhong.org/api/aaaa/add done