redirecting output from find

E

emannion

Hi,

I have a script that finds files like this:


find(\&finds, $dir);

sub finds {

return unless -f;

if ( $_ =~ /^core./ ){
@ls = `ls -l $File::Find::name`;
fail("Core file $_ found in: $File::Find::dir ", "MEDIUM");
print PX_HEALTH_REPORT "@ls \n";
$flag = 1;
}
}


This works fine but the error output from find gets printed to the
screen like this:


Can't cd to (/var/spool/) mqueue : The file access permissions do not
allow the specified action.
Can't cd to (/var/spool/cron/) crontabs : The file access permissions
do not allow the specified action.
Can't cd to (/var/spool/cron/) atjobs : The file access permissions do
not allow the specified action.
Can't cd to (/var/adm/) SRC : The file access permissions do not allow
the specified action.
Can't cd to (/var/adm/) cron : The file access permissions do not
allow the specified action.


Can someone tell me how to redirect this output somewhere else. I
still want some output to be printed to the screen so a change in the
code for this function would be helpful.

All help appreciated
Enda
 
M

Michele Dondi

if ( $_ =~ /^core./ ){

This is just as if you had stepped on my thumb. Use

if ( /^core./ ) { ... }
# or
if ( $var =~ /^core./ ) { ... }

BTW: how strange a regex
@ls = `ls -l $File::Find::name`;

This is more as if you had stabbed me in the back.
Well, a quick way to gather and display some info, but since you cd in
the browsed directory, it should *not* do what you mean.
This works fine but the error output from find gets printed to the
screen like this:


Can't cd to (/var/spool/) mqueue : The file access permissions do not
allow the specified action.
[snip]

Then it *can't* "work fine". There are some directories you're not
accessing. If you don't want to anyway, then you'd better check for
yourself and prune.

Or see if the no_chdir find() param helps.
Can someone tell me how to redirect this output somewhere else. I
still want some output to be printed to the screen so a change in the
code for this function would be helpful.

Well, supposedly those are errors printed to STDERR. From your shell
redirect it to some place where it doesn't annoy you. Most probably,
with 2>/dev/null


Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top