count how many time each "IP" visit URL with specific "word"

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
hello

i want to make bash scripts to search in access_log to count how many time each "IP" visit URL that contain word "newspaper".


the output will be like this

100 37.130.227.133 - - [16/May/2013:09:48:26 +0300] "GET /en/index.php?name=newspaper
40 94.23.73.182 - - [16/May/2013:09:48:26 +0300] "GET /english/index.php?name=newspaper
20 199.48.147.35 - - [16/May/2013:09:48:26 +0300] "GET /arab/page.php?name=newspaper
70 88.208.90.1 - - [16/May/2013:09:48:26 +0300] "GET /ar/result.php?name=newspaper

100 37.130.227.133 mean the IP "37.130.227.133" visit url that contain "newspaper" 100 time
 

040hosting

Registered
Aug 6, 2012
1
0
1
cPanel Access Level
DataCenter Provider
cat filemame |grep "keyword" | awk {'print $1'} | sort -n | uniq -c | sort -n

Change the filename and the keyword to your liking.

find is useful for a thousand and one things so an easy one to remember ;)
last sort -n is not needed but gives a nicer few from low to high.

Hope this helps.
 

whm-expert

Active Member
Nov 10, 2012
40
0
6
cPanel Access Level
DataCenter Provider
hello
when i use your cmd in
cat /usr/local/apache/domlogs/* |grep "newspaper" | awk {'print $1'} | sort -n | uniq -c | sort -n

this is the output
cat: /usr/local/apache/domlogs/indust: Is a directory
cat: /usr/local/apache/domlogs/indust: Is a directory
cat: /usr/local/apache/domlogs/moe: Is a directory



if i use this cmd
grep -RPnDskip "(newspaper)" /usr/local/apache/domlogs/* | awk {'print $1'} | sort -n | uniq -c | sort -n

this is the output
1 /usr/local/apache/domlogs/indust/indust.com:60267:37.236.92.66
1 /usr/local/apache/domlogs/indust/indust.com:60267:37.236.92.66
1 /usr/local/apache/domlogs/moe/moedu.com:1066497:85.114.108.77

please can you explain what is mean?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,203
363
Hello :)

While there are several knowledgeable administrators on the cPanel forums, keep in mind that questions about specific bash scripting will often yield more replies on other websites that focus more on system administration than the cPanel software itself (e.g. LinuxQuestions.org or CentOS forums).

Thank you.