Count the top ten IPs in Apache log files and arrange them from more to less
May by FANDLR
Filed under Linux
Leave a Comment
Solution 1:cat Access_log | awk ' {print '} ' | Sort | uniq-c | Sort-n-R | HEAD-10 Solution 2:cat Access_log | Awk-f "--" ' {print $} ' | Sort-t. | uniq-c | Sort-n-R | Head-10
awk ' {a[$1] + = 1;} END {for (I in a) printf ("%d%s\n", a[i], i);} ' log file | Sort-n | Tail
First, you use awk to get a list, then sort it out, and finally use tail to take the last 10.
The above parameters can be slightly modified to display more data, such as the tail plus-n parameters, and other log format commands may need to be modified.
the most frequently joined IP addresses in the current Web server
#netstat-ntu |awk ' {print $} ' |sort | uniq-c| Sort-nr
View The top 10 most visited IPs in a log
#cat access_log |cut-d "-F 1 |sort |uniq-c | Sort-nr | awk ' {print $} ' | Head-n |less
See more than 100 IPs in the log
#cat access_log |cut-d "-F 1 |sort |uniq-c | awk ' {if (>) print $ |sort-nr} ' |less
View the most recently accessed files
#cat access_log |tail-10000|awk ' {print $7} ' |sort|uniq-c|sort-nr|less
View pages that have been accessed more than 100 times in the log
#cat Access_log | Cut-d '-F 7 | Sort |uniq-c | awk ' {if (>) print $} ' | Less
Statistics a URL, the number of visits per day
#cat access_log|grep ' 12/aug/2009′|grep '/images/index/e1.gif ' |wc|awk ' {print $} '
Most visited pages in the first five days
#cat Access_log|awk ' {print $7} ' |uniq-c |sort-n-r|head-20
See what the IP is doing in the log.
#cat Access_log | grep 218.66.36.119| awk ' {print $1″\t ' $7} ' | Sort | uniq-c | Sort-nr | Less
List files that have been transmitted for longer than 30 seconds
#cat Access_log|awk ' ($NF >) {print $7} ' |sort-n|uniq-c|sort-nr|head-20
List the most time-consuming pages (more than 60 seconds)
#cat access_log |awk ' ($NF > && $7~/\.php/) {print $7} ' |sort-n|uniq-c|sort-nr|head-100
Statistics on Apache logs