Saturday, June 10, 2006

Who Visits your Website - Apache logs

There are couple of Programs like Awstats, PhpMyVisites etc ...
which can calculate the statistics of Visitors from your Apache Logs.

But what if you are lazy like me to configure those stuff,
Create logins etc... and check the graph.

Heres a easy way out :

[root@localhost unixbox]# cat /var/log/httpd/access_log
| sort | uniq -w15 -c | cut -f 1 -d- | sort -r -g


The Left hand side will list the total number of hits from the IP addresses.

For example has visited us 10 times,
Now if you want to check the date and time of the visit grep
that particular IP address in access_log.

Now suppose you want the total number of hits for a Particular Directory,
then you may try this, Say For eg. /ram/ directory and print a count
(from greatest to least).

add this " grep -e /ram " , like the below command will list IP addresses
accessing /ram folder.

[root@localhost unixbox]# cat /var/log/httpd/access_log
|grep -e /ram/ | sort | uniq -w15 -c | cut -f 1 -d- | sort -r -g

Thanks to this article