1. #!/bin/bash
    2. # 日志格式: $remote_addr - $remote_user [$time_local] "$request" $status
    3. $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"
    4. LOG_FILE=$1
    5. echo "统计访问最多的10个IP"
    6. awk '{a[$1]++}END{print "UV:",length(a);for(v in a)print v,a[v]}' $LOG_FILE |sort
    7. -k2 -nr |head -10
    8. echo "----------------------"
    9. echo "统计时间段访问最多的IP"
    10. awk '$4>="[01/Dec/2018:13:20:25" && $4<="[27/Nov/2018:16:20:49"{a[$1]++}END{for(v
    11. in a)print v,a[v]}' $LOG_FILE |sort -k2 -nr|head -10
    12. echo "----------------------"
    13. echo "统计访问最多的10个页面"
    14. awk '{a[$7]++}END{print "PV:",length(a);for(v in a){if(a[v]>10)print v,a[v]}}'
    15. $LOG_FILE |sort -k2 -nr
    16. echo "----------------------"
    17. echo "统计访问页面状态码数量"
    18. awk '{a[$7" "$9]++}END{for(v in a){if(a[v]>5)print v,a[v]}}'