redirecting output from find

Discussion in 'Perl Misc' started by emannion@gmail.com, Aug 13, 2007.

  1. Guest

    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
    , Aug 13, 2007
    #1
    1. Advertising

  2. On Mon, 13 Aug 2007 13:43:30 -0000, 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^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Aug 13, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Aspinall
    Replies:
    0
    Views:
    354
    Paul Aspinall
    Feb 26, 2006
  2. Olivier Merigon

    Textfield output redirecting

    Olivier Merigon, May 3, 2004, in forum: Java
    Replies:
    1
    Views:
    893
  3. Birch
    Replies:
    3
    Views:
    1,008
    Birch
    Oct 21, 2003
  4. Eddie Parker

    RE: Redirecting system output quietly

    Eddie Parker, Nov 16, 2004, in forum: Python
    Replies:
    4
    Views:
    392
    Donn Cave
    Nov 16, 2004
  5. Jon Hawkins
    Replies:
    2
    Views:
    100
    Robert Klemme
    Aug 3, 2007
Loading...

Share This Page