The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Security' started by whm-expert, May 21, 2013.

  1. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    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
     
  2. 040hosting

    040hosting Registered

    Joined:
    Aug 6, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    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.
     
  3. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    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?
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page