grep - why does this crash?

Red Squirrel

No Lifer
May 24, 2003
68,315
12,549
126
www.anyf.ca
I'm running this command from within / on a CentOS server:

grep -R tempdelete.pl *

Runs for a while but then crashes with Segmentation fault.

Why is this? I've seen seg faults in my own programs still in devel stage caused by an error, but not in a standard application that is not beta.


Is there another way I can accomplish this? I need to find any files that reference tempdelete.pl in them. It's a cron job that keeps failing because the file does not exist, and its not in cron tab, so want to know what keeps trying to call it every day.
 

lousydood

Member
Aug 1, 2005
158
0
0
find is probably better suited to this job than grep -R. \{\} expands to the current filename. \; ends the command. I include /dev/null so that grep will spit out the filename (which it won't do if there is only one file to search at a time).

find / -exec grep tempdelete.pl /dev/null \{\} \;

You will probably want to use some of the options to find to restrict the search a bit, there may be some files on your computer which would cause this to run for far too long.
 

Kakumba

Senior member
Mar 13, 2006
610
0
0
Quick note: the backslashes before curly braces may not be needed. They are not needed on any of my machines anyway. Which CentOS, 5.1? I just tried on a 5.1 machine, and nothing yet. So, I would come up with something like

#:find / -type f -exec grep "tempdelete.pl" {} \; But that could still do with some restrictions, and ideally run it on certain directories only, running over the whole FS may be pointless, and you will get a tonne of useless permission denied messages.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Why is this? I've seen seg faults in my own programs still in devel stage caused by an error, but not in a standard application that is not beta.

It segfaulted because of a bug with it. Something with it is wrong. I run commands like that all the time and it works just fine with grep. It should not ever segfault, at worst it will choke and error out, more or less gracefully.

.--------------------------

You can go individually file by file.

I go something like this sometimes:

ls |while read i; do if grep searchstring "${i}" > /dev/null ; then echo "${i}" ; fi ; done

Pretty inelegant, but it gets the job done and I always remember how to do a loop without having to look it up.