redirecting output from find
am 13.08.2007 15:43:30 von 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
Re: redirecting output from find
am 13.08.2007 16:01:07 von Michele Dondi
On Mon, 13 Aug 2007 13:43:30 -0000, emannion@gmail.com wrote:
> 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
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,