每日一shell(七)统计站点的IP和PV

通过nginx日志文件统计出所有的IP和PV,列出排名前10的IP,以confluence知识库系统为例:

nginx日志文件为/var/log/nginx/access.log

# wc -l /var/log/nginx/access.log 
95146 /var/log/nginx/access.log

shell脚本:

# vim accessnum.sh 
#!/bin/bash
#writen by Gavin Zhao
#This shell will print how many users access your server by web
awk '/itks/ {print $1}' /var/log/nginx/access.log | sort -rn | uniq -c | sort -rn | awk '{$2 ~ /10./ && $2!="10.1.46.189" && (tot=to
t+$0)};END{print NR,tot}'  > /root/script/num.txt 2> /dev/null
ip=`awk '{print $1}' /root/script/num.txt`
pv=`awk '{print $2}' /root/script/num.txt`
echo "截止到目前IT知识库的总访问量:$pv"
echo "截止到目前IT知识库的总访问IP数:$ip"
echo "排名前10的IP如下:"
awk '/itks/ {print $1}' /var/log/nginx/access.log | sort -rn | uniq -c | sort -rn | awk ' $2 ~ /10./ && $2 !~ /10.1.46.189|10.1.116.
4/ && NR<=12 {print $2}'
chmod +x accessnum.sh

每日一shell(七)统计站点的IP和PV



本文转自 喵来个鱼 51CTO博客,原文链接:http://blog.51cto.com/m51cto/2071193,如需转载请自行联系原作者

上一篇:躲在繁华的角落里,冷读世界


下一篇:LeetCode 练习——260. 只出现一次的数字 III