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.

grep all .asp file in specific directory that doesn't not contain a word

Discussion in 'Security' started by whm-expert, May 16, 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 a bash script to grep all .asp file in specific directory that doesn't not contain a word like "program by x team" for security reason.

    i mean if the grep command find these word"program by x team", it will ignore the file in result.

    if the grep command doesnt find the words "program by x team" in a file it will print the fill path for the file.
     
  2. ThinIce

    ThinIce Well-Known Member

    Joined:
    Apr 27, 2006
    Messages:
    346
    Likes Received:
    7
    Trophy Points:
    18
    Location:
    Disillusioned in England
    cPanel Access Level:
    Root Administrator
    Take a look at man grep

    I'd imagine you want something like grep -v "program by x team"

    As:

    -v, --invert-match Invert the sense of matching, to select non-matching lines
     
  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
    i use grep -v , but it ignore only the line that contain "program by x team",
    what i need to ignore the whole file
     
  4. ThinIce

    ThinIce Well-Known Member

    Joined:
    Apr 27, 2006
    Messages:
    346
    Likes Received:
    7
    Trophy Points:
    18
    Location:
    Disillusioned in England
    cPanel Access Level:
    Root Administrator
    The following is probably more appropriate then

    -L, --files-without-match
    Suppress normal output; instead print the name of each input
    file from which no output would normally have been printed. The
    scanning will stop on the first match.
     
  5. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    Hello,

    How about this:
    cd into the folder you mention having the .asp files.
    Code:
    du -ha | grep -i -o "\./.*asp" | xargs grep -i -n "$1" |grep -v "program by x team"
    It should show only the files that doesn't contain your pattern and also ignore the files that does contain it. Warning ! This will show/output the content of all your .asp files that doesn't contain your pattern.
     
    #5 InterServed, May 17, 2013
    Last edited: May 17, 2013
  6. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
    i try to use your could but it still not give me the right result
     
  7. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    Probably my wrong understanding on what your trying to accomplish.

    If you wish the exclude the files that contain your pattern , and you still wish to grep them , that means there should be a second pattern or am i wrong ? You might need to provide a bit more accurate details , probably with some example-data so people could probably help you more.
     
  8. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
    briefly, i need to do this:

    list all ".asp" files that do not contain the words "program by x team".
    if the file contain the word "program by x team" in any line of a specific file it will ignore it in results.

    because the result list only the files that don't contain the words "program by x team"
     
  9. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    Did a small test with the command i provided you and for me it seems like it should do what you asked for:

    Code:
    -rw-r--r--   1 root root    6 May 19 14:30 1.asp
    -rw-r--r--   1 root root    6 May 19 14:31 2.asp
    -rw-r--r--   1 root root    6 May 19 14:31 3.asp
    -rw-r--r--   1 root root   18 May 17 13:05 4.asp
    On my testing , only file-name 4.asp contains your pattern:
    Code:
    1.asp -> 1asp-content
    2.asp -> 2asp-content
    3.asp -> 3asp-content
    4.asp -> program by x team
    Code:
    root@nlsrv1 [~/asp-test]# du -ha | grep -i -o "\./.*asp" | xargs grep -i -n "$1" |grep -v "program by x team"
    ./3.asp:1:3asp-content
    ./1.asp:1:1asp-content
    ./2.asp:1:2asp-content
    So as you can see , it only listed the files that doesn't contain your pattern "program by x team".
    If you wish to search for something specific after ignoring the files that contains "program by x team" , then you could replace the "$1" from my command with your search pattern.
     
    #9 InterServed, May 19, 2013
    Last edited: May 19, 2013
  10. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
    hello
    thank you for your answer
    i try to execute your cmd and this is the output in ssh
    Note: i replace .asp with .php
    root@server [~]# du -ha | grep -i -o "\./.*php" | xargs grep -i -n "$1" |grep -v "program by x team"
    output
    grep: ./.cpanel/datastore/_usr_bin_php: No such file or directory

    please can you tell me how can i search in a specific website like
    /home/website/www/
     
  11. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    Try to go inside the directory that you wish to search first , like " cd /home/website/public_html/ "
     
  12. whm-expert

    whm-expert Active Member

    Joined:
    Nov 10, 2012
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    DataCenter Provider
    ok, i try this

    du -ha | grep -i -o "\./.*php" | xargs grep -i -n "$1" |grep -v "program by x team"

    it list all files in directory, please check the output, but all these files dont contain "program by x team"

    output

    Binary file ./en/function/news.php matches
    Binary file ./en/function/topmenue.php matches
    Binary file ./en/function/mysql.php matches
    Binary file ./en/function/function.php matches
    Binary file ./en/function/security.php matches
    Binary file ./en/function/sources.php matches
    root@alsco [/home/itech/www]#
     
    #12 whm-expert, May 19, 2013
    Last edited: May 19, 2013
  13. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    255
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    DataCenter Provider
    Isn't that what you wanted ?
     
  14. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    As mentioned, the output of the command provided by InterServed appears to match your requirements. Is there another result you are seeking?

    Thank you.
     
Loading...

Share This Page