统计APACHE ACCESS.LOG IP访问记录
可以根据自己的需要,统计很多,每个IP访问多少个页面等等!

cat access.log-20090904 |awk '{print $3}'|sort|uniq -c|sort -rn|wc -l

详解:下面是一个例子:

cat 是读取这个文件。

1147753394.079 2 220.139.141.61 TCP_DENIED/403 1354 CONNECT 222.124.24.93:25 - NONE/- text/html
1147753395.652 0 61.228.130.169 TCP_DENIED/403 1352 CONNECT 203.84.195.1:25 - NONE/- text/html
1147753395.754 0 61.228.135.187 TCP_DENIED/403 1350 CONNECT 203.86.1.30:25 - NONE/- text/html
1147753398.042 3 61.228.131.15 TCP_DENIED/403 1354 CONNECT 81.169.162.54:25 - NONE/- text/html

awk '{print $3}' 是apache log的第三个字段

220.139.141.61
61.228.130.169

[root@localhost~]# cat access.log | awk '{print $3}'

61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.99
61.228.130.187

sort是排序,

[root@localhost~]# cat access.log | awk '{print $3}'|sort

61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106
61.228.134.106

uniq -c 打印每一重复行出现的次数。

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c
6 220.139.141.61
6 61.228.130.169
12 61.228.130.187
6 61.228.131.15

sort -rn 对排序求逆,n为域号,使用此域号开始分类。

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c|sort -rn
24 61.228.134.106
12 61.228.130.187
6 61.228.135.187
6 61.228.134.99
6 61.228.131.15
6 61.228.130.169
6 220.139.141.61
wc -l 统计行数的

[root@localhost~]# cat access.log | awk '{print $3}'|sort|uniq -c|sort -rn|wc -l
7

05-11 22:49