Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a particular word from a file in a server

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi All!

I have a problem ,how i can find a file.If it has some hazadrous words which will affect my application running in the server.

For example if i need to find the files in the server having the name test.txt which has a word "test=hack" in the test.txt what is the command i have to use in the server.


Then i will import the command in a perl script in which it will sent me a alert mail stating this directory contains test.txt with the word "test=hack".

Thanks for any help

Thendal:)
 
I'm not much of a programmer with perl but if you are you can use snippets of code
from a simple search cgi that matt's script archive has at:


Though its a cgi program the same code could be utilized at command line level.
The simple search script would at least tell you where a file with search criteria
would exist. This script has a "@files" attribute so you can set a few things as
for directories to search and file extensions and so fourth and have it pushed into
a fileseach.txt to examine and also create more code to take care of it leaving the text
file as a log. well anyway something like that.

This also can be done using shell commands and setup a shell script using things like
find, grep, cat, cut umoung the few.

Maxit
 
Thanks matt ,I am exactly looking out some command in unix
like

find "this text" contain in the "file name" from /root/

if it returns some value then i will write perl script to send a alert mail.

Thank you very much maxit.
 
The simplest way (maybe not the best) to do what you want is to use a very powerful adm. tool, the "find" command

Try : find /root -name <pattern you wanna match> -ls > file

And if you want to look for a specific pattern inside the test.txt file,

find /root -name <pattern> -print | xargs grep <pattern>

This will print as output the lines matched by the second pattern.

Hope it will help.

Worthy


 
Thanks worthy!

It works thank you very much ...

I excuted the command and try to get the output in a text file.(in order to process in a perl file so that i write a script according to the values i receive from the text file)

The command is

find /root -name test.txt -print | xargs grep danger

but the output is coming in one single line(/root/bla/bla/text:danger/root/bla/bla/text2:danger)

,Is there any way i can able to break the output

like
/root/bla/bla/text:danger
/root/bla/bla/text2:danger

adding a newline in every catch

Thanks

:)

Thendal;-)

 
Thanks worthy!

It works thank you very much ...

I excuted the command and try to get the output in a text file.( so that i write a script according to the values i receive from the text file)

The command is

find /root -name test.txt -print | xargs grep danger

but the output is coming in one single line(/root/bla/bla/text:danger/root/bla/bla/text2:danger)

,Is there any way i can able to break the output

like
/root/bla/bla/text:danger
/root/bla/bla/text2:danger

adding a newline in every catch

Thanks

:)

Thendal;-)

 
Happy that it helped.

Keep on working on your problem. It seems that you did not exactly obtain the desired result.

If your file contains the following data

...
/root/bla/bla/text:danger
/root/bla/bla/text2:danger
...

the grep command will give you as output these two lines matched. What I'm saying is that you don't have to break the output. It must already be.

--
Worthy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top