How to find the total number of connections for a cPanel account from the log files – command-line(SSH) option

Yes, it’s very useful tip to find the grand total number of connections in your domain hosted in a cPanel server. It is very helpful to analyse the domain traffic from command-line. Here I am selecting the “domlog” for calculating the total number of connections per day. The “domlog” file is located under the “/usr/local/apache/domlogs/yourdomain/”.

Steps to find the total number of connections:

Step 1 : Login to the server as root.
Step 2 : Change the directory to domlog’s as mentioned.

cd /usr/local/apache/domlogs/yourdomain/

Change yourdomain with your account’s username.

Step 3 : Then, analyse and find out the total number of connections from the domlog file, yourdomain.com
See the below pasted sample output for the domlog;

67.195.51.209 - - [03/Apr/2014:20:03:05 -0700] "GET /the-screen-command/ HTTP/1.1" 200 56039 "http://pipes.yahoo.com/pipes/pipe.info?_id=rDJysE3I3BG0HxC2l7okhQ" "YahooCacheSystem"
67.195.51.209 - - [03/Apr/2014:20:03:20 -0700] "GET /the-screen-command/ HTTP/1.1" 200 56125 "http://pipes.yahoo.com/pipes/pipe.info?_id=rDJysE3I3BG0HxC2l7okhQ" "YahooCacheSystem"
220.2xx.136.xxx - - [03/Apr/2014:20:04:24 -0700] "GET /root HTTP/1.1" 301 342 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
111.74.238.22 - - [03/Apr/2014:20:04:24 -0700] "GET /grep-command-string-options/ HTTP/1.0" 200 64689 "https://crybit.com/grep-command-string-options/" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36"
220.2xx.136.xxx - - [03/Apr/2014:20:04:24 -0700] "GET /root/ HTTP/1.1" 404 57340 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
220.2xx.136.xxx- - [03/Apr/2014:20:04:28 -0700] "GET /favicon.ico HTTP/1.1" 200 - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
98.118.242.235 - - [03/Apr/2014:20:04:31 -0700] "GET /wp-content/uploads/2014/03/top.png HTTP/1.1" 200 55229 "-" "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"

We can select the date entry [03/Apr/2014] to find out the total number of connections per day. Also, by using the “awk”, “sort” and “uniq” we can sort-out the connections per day.

Syntax:

grep 03/Apr/2014 yourdomain.com |awk {'print $1'}|sort -nr|uniq -c|sort -nr|wc -l

grep 03/Apr/2014 : list all connections on that day.
awk {‘print $1’} : It will print the first line from that log, that’s the IP sections.
uniq -c : gives you a uniq result.

Example:

[email protected] [/usr/local/apache/domlogs/domain]# grep 03/Apr/2014 domain.com |awk {'print $1'}|sort -nr|uniq -c|sort|wc -l
1283

That means a total of 1283 IP addresses were connected to your domain on 03/Apr/2014.
That’s it ..! 🙂

 

Related posts:
Important log files for Plesk server
Important log file paths for Directadmin server
Important exim log file paths in WHM/cPanel & Directadmin

Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *