Search entire system for files containing certain word(s)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search entire system for files containing certain word(s)
# 1  
Old 01-06-2011
Search entire system for files containing certain word(s)

I am trying to create a script that will report (email and ftp results) on any file, system wide, that has the word password= in it. (and any variation of password=). Basicaly looking for any plain text passwds. I figured the easiest way would be like this......

Code:
for i in `cat find-pw.dat`
 do
 grep -i $i= `find / -type f ` >> out.log
done

But, on Linux I get "grep: /bin/grep: cannot execute [Argument list too long]" and CPU usage hits 99%
on AIX I get "0403-029 There is not enough memory available now."

Is there a more effective cpu/mem friendly way to do this?

Thanks
# 2  
Old 01-06-2011
Try:
Code:
while read line
do
   find / -type f | xargs grep -i "${line}=" >> out.log
done < find-pw.dat

# 3  
Old 01-06-2011
(Deliberately not posting solution).
# 4  
Old 01-06-2011
I got this to work, however it takes forever to run. This isn't what it sounds like methyl Smilie

Code:
for i in `cat find-pw.dat`
 do
 find / -type f -exec grep $i= {} \; >> out.log
done

Thanks anurag your versions gives me better output to sort through.

Last edited by theninja; 01-06-2011 at 05:06 PM..
# 5  
Old 01-06-2011
What process produced the file find-pw.dat ?


Btw. I have no idea where the dubious construct
"for i in open_ended_selection"
comes from. The only place I have ever seen it is this board and always from posters in India. Is this construct taught in some commonly available training course notes in India?
The construct has no use whatsoever in the commercial world.
# 6  
Old 01-07-2011
find-pw.dat is a manually created file containing every possible spelling of the word.
Not sure what they teach in india, I was taught that many years ago when I started in Unix by an old white guy. I disagree it has no use whatsoever. I have worked for several fortune 500 companies and I've seen this at all of them. It works great, so I'm not sure why you seem to despise it.

Next I need to create some filters on the output, you would not beleive how many hits on the word passw* this returns.

I think this will be easier in perl.

Last edited by theninja; 01-07-2011 at 12:32 PM..
# 7  
Old 01-08-2011
Quote:
I'm not sure why you seem to despise it.
Mainly because it does not correctly deal with input lines containing space characters and it is can easily break the maximum command line length in common Operating Systems such as IBM's AIX.
As a troubleshooter since early unix I found that script authors using "for" with open-ended lists proved to be the most common scripting mistake. I've even seen it in manufacturer-supplied cleanup crons in Unix SV R3 .

I have no problem for with finite lists with the values in double quotes. The issue is with open-ended lists.


Btw. Your script would run a lot faster if you test the result of the unix "file" command first to eliminate non-ascii files which are unsuitable for a character string "grep". I have used this technique to search over 100,000 files where only about 2,000 were suitable for searching.
Afterthought: The matching process would be a lot quicker with "egrep" on a file-by-file basis.

Last edited by methyl; 01-08-2011 at 11:30 PM.. Reason: grammar
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. UNIX for Advanced & Expert Users

Cut a word between two strings and repeat the same in the entire file

in the below data i need to search for the word typeMismatch and then traverse back to find the filename of that particular mismatch. Like this we have to get all the file names which has error in them. How can i acheive this. I tried use sed or awk but not able to achevie the same. Sample... (2 Replies)
Discussion started by: ATWC
2 Replies

3. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word "description" excluding weird characters like $&lmp and without html tags in the new file output.txt. Help me. Thanx in advance. I have attached the input... (4 Replies)
Discussion started by: sachit adhikari
4 Replies

4. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Linux

How to search in ms word files and pdf's

Hi, Please let me know if there is a unix command or any shell script which can do a search for a text in ms-word files, pdf'd and in excel files. Please let me know if there is a solution for this challenge. Thanks, Kesava. (4 Replies)
Discussion started by: kesava
4 Replies

7. Solaris

How to search for a word in multiple files

Hi, I want to find for a particular word which is existing in different files and folders under the parent directory. What command can I use to retrieve all the file names which is having the word. (1 Reply)
Discussion started by: rogerben
1 Replies

8. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

9. UNIX for Dummies Questions & Answers

How to search files containing a specific word in the content

Hi all, Lets say I have 3 files a.txt and b.txt and c.txt. a.txt has the following text ==================== apple is good for health b.txt has the following text ==================== apple is pomme in french c.txt has the following text ==================== orange has citric acid... (1 Reply)
Discussion started by: amjath78
1 Replies

10. UNIX for Dummies Questions & Answers

search for certain word in a files from directory

hi can i know how to get the file name of any files containing for example "abc" from a number of files in a directory? i tried "ls -ltrc | grep abc" but no resulted generated. thanks in advance. (1 Reply)
Discussion started by: legato
1 Replies
Login or Register to Ask a Question