#!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin # Nginx 日志格式: # log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for" $upstream_addr'; LOG_FILE=$1 echo "--------------统计访问最多的10个IP-----------------------------" awk '{a[$1]++} END {print "UV:", length(a)}' $LOG_FILE awk '{a[$1]++} END {for(v in a) print v, a[v]}' $LOG_FILE | sort -k2 -nr | head -10 echo "--------------统计时间段访问最多的10个IP-----------------------" awk '$4 >= "[13/Jul/2020:13:00:00" && $4 <= "[13/Jul/2020:17:00:00" {a[$1]++} END {for(v in a) print v, a[v]}' $LOG_FILE | sort -k2 -nr | head -10 echo "--------------统计访问最多的10个页面---------------------------" # awk '{a[$7]++} END {print "PV:", length(a)}' $LOG_FILE echo "PV: `awk '{print $7}' $LOG_FILE | wc -l`" awk '{a[$7]++} END {for(v in a) print v, a[v]}' $LOG_FILE | sort -k2 -nr | head -10 echo "--------------统计访问页面状态码数量最多的10个页面-------------" awk '{a[$7" "$9]++} END {for(v in a) print v, a[v]}' $LOG_FILE | sort -k3 -nr | head -10