您的位置:首页 > 运维架构 > Shell

工作中shell命令分析Apache网站日志大全

2015-03-26 17:11 549 查看
1.获得访问前10位的ip地址
cat access_log |awk '{print $1}'|sort|uniq -c|sort -nr|head -10
2.访问次数最多的文件或页面,取前20
cat access.log|awk ‘{print $11}’|sort|uniq -c|sort -nr|head-20
3.列出传输最大的几个exe文件
cat access.log |awk ‘($7~/\.exe/){print $10 ” ” $1 ” ”$4 ” ” $7}’|sort -nr|head -20
4.列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数
cat access.log |awk ‘($10 > 200000 && $7~/\.exe/){print $7}’|sort -n|uniq -c|sort -nr|head -100
5.如果日志最后一列记录的是页面文件传输时间,则列出到客户端最耗时的页面
cat access.log |awk ‘($7~/\.php/){print $NF ” ” $1 ” ”$4 ” ” $7}’|sort -nr|head -100
6.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cat access.log |awk ‘($NF > 60 && $7~/\.php/){print $7}’|sort -n|uniq -c|sort -nr|head -100
7.列出传输时间超过30 秒的文件
cat access.log |awk ‘($NF > 30){print $7}’|sort-n|uniq -c|sort -nr|head -20
8.统计网站流量(G)
cat access.log |awk ‘{sum+=$10} END {printsum/1024/1024/1024}’
9.统计404的连接
awk ‘($9 ~/404/)’ access.log | awk ‘{print $9,$7}’ |sort

10.[b]统计http status.[/b]
cat access.log |awk ‘{counts[$(9)]+=1}; END {for(codein counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn
11.蜘蛛分析
查看是哪些蜘蛛在抓取内容。
/usr/sbin/tcpdump -i eth0 -l -s 0 -w - dst port 80 | strings | grep -iuser-agent | grep -i -E 'bot|crawler|slurp|spider'
若有不足之处,请多多指教!
本文出自 “9527” 博客,请务必保留此出处http://liangey.blog.51cto.com/9097868/1625057
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: