• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

grep - why does this crash?

Red Squirrel

No Lifer
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.
 
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.
 
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.
 
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.
 
Back
Top