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

前端之家收集整理的这篇文章主要介绍了每日一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

猜你在找的Bash相关文章