shell脚本分析nginx日志

178.255.215.86 - - [04/Jul/2013:00:00:31 +0800] "GET /tag/316/PostgreSQL HTTP/1.1" 200 4779 "-" "Mozilla/5.0 (compatible; Exabot/3.0 (BiggerBetter); +http://www.exabot.com/go/robot)" "-"- 
178.255.215.86 - - [04/Jul/2013:00:00:34 +0800] "GET /tag/317/edit HTTP/1.1" 303 5 "-" "Mozilla/5.0 (compatible; Exabot/3.0 (BiggerBetter); +http://www.exabot.com/go/robot)" "-"- 
103.29.134.200 - - [04/Jul/2013:00:00:34 +0800] "GET /code-snippet/2022/edit HTTP/1.0" 303 0 "-" "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/17.0 Firefox/17.0" "-"- 
103.29.134.200 - - [04/Jul/2013:00:00:35 +0800] "GET /user/login?url=http%3A//outofmemory.cn/code-snippet/2022/edit HTTP/1.0" 200 4748 "-" "Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/17.0 Firefox/17.0" "-"-

 

以下脚本都是基于上面日志格式的,如果你的日志格式不同需要调整awk后面的参数。

分析日志中的UserAgent

cat access_20130704.log | awk -F "\""'{print $(NF-3)}'| sort | uniq -c | sort -nr | head -20

上面的脚本将分析出日志文件中最多的20个UserAgent

分析日志中那些IP访问最多

cat access_20130704.log | awk '{print $1}'| sort | uniq -c | sort -nr | head -20

分析日志中那些Url请求访问次数最多

cat access_20130704.log | awk -F "\""'{print $(NF-5)}'| sort | uniq -c | sort -nr | head -20


已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐
  • —软件人才免语言低担保 赴美带薪读研!—



你可能感兴趣的:(shell,脚本,分析)