Search Posts on Binpipe Blog

Code Snippet: To find the number of hits per domain in a Shared Server (CPanel on Linux)

You can run the following command line recipe to find the number of hits per domain in a Shared Server (CPanel on Linux):

 a=$(date +%s); touch /root/$a; for domains in `cat /etc/userdomains | cut -d : -f 1`; do wc -l /etc/httpd/domlogs/$domains >> /root/$a 2>/dev/null; done; cat /root/$a | grep -v "0 /etc/" | sort -nk1 | tail -6 >> /root/test.txt; rm -rf /root/$a; for ((c=1; c<=6; c++)); do awk "NR==$c{print;exit}" /root/test.txt | awk {'print $2'} | xargs head -n1 | cut -d= -f1 | sed '/^$/d' | awk {'printf "Since " $4 "] there were "'}; awk "NR==$c{print;exit}" /root/test.txt | awk {'printf $1 " hits to "'}; awk "NR==$c{print;exit}" /root/test.txt | awk -F/ {'print "["$5"]"'}; done; rm -f /root/test.txt;


The output will something be like this:

Since [18/Jun/2013:13:06:25] there were 5163 hits to [test.com]
Since [18/Jun/2013:13:04:46] there were 7402 hits to [test1.com]
Since [18/Jun/2013:13:06:43] there were 8586 hits to [test2.com]
Since [18/Jun/2013:13:04:58] there were 9808 hits to [test3.info]
Since [18/Jun/2013:13:04:57] there were 15218 hits to [test4.com]
Since [18/Jun/2013:13:04:51] there were 26965 hits to [test5.com]

No comments:

Post a Comment

Hi, Leave a comment here and one of the binary piper's will reply soon :)