in reply to Re^6: Restrict file search within current filessystem using wanted subroutine
in thread Restrict file search within current filessystem using wanted subroutine

Hi madparu,

Unfortunately I don't know enough about all of those systems to give you a good answer. But since AIX, HP-UX and Solaris are (in various versions) POSIX certified, and none of perlport, perlsolaris, perlhpux, or perlaix seem to mention any issues with stat on those systems, I'd make the educated guess that the "dev" field of stat should work the same on all of those OSes. Update: Just to be clear, I don't mean that the device IDs will be the same across those OSes - what I mean is that I think the above method of detecting file system boundaries should work on each of those OSes.

Of course, you can just try it out on each system:

perl -le 'print "$_\tdev=",(stat)[0] for @ARGV' /var /var/log

Regards,
-- Hauke D

  • Comment on Re^7: Restrict file search within current filessystem using wanted subroutine
  • Download Code

Replies are listed 'Best First'.
Re^8: Restrict file search within current filessystem using wanted subroutine
by Anonymous Monk on May 12, 2016 at 12:34 UTC
    Hi Hauke,

    I managed to run the script itself on all the flavours and it works fine. thank you!!

    --madparu
Re^8: Restrict file search within current filessystem using wanted subroutine
by Anonymous Monk on May 17, 2016 at 15:25 UTC
    Hi Hauke,

    I tried excluding a specific file (say /var/log/test.out) as below:

    return if ($File::Find::name =~ test.out);

    This seems to work. but this might exclude test.out if it finds in any other filesystem. so tried to use the below code but doesn't work.

    return if ($File::Find::name =~ /^\/var\/log\/lastlog);

    Whats the best way to exlcude test.out from /var/log?

      Hi Anonymous,

      The issue is that if you tell your script to search a relative pathname (such as the default "."), then $File::Find::name will not be an absolute pathname either. Have a look at the Basic debugging checklist - this tells you that you should print your values, such as print $File::Find::name;, and you can find this out for yourself.

      One way to fix this: 1. At the top of your script, add "use File::Spec::Functions qw/rel2abs/;" (see the function rel2abs in File::Spec), and 2. replace "shift || '.'" with "rel2abs(shift || '.')" - now all your search paths and therefore $File::Find::name should be absolute pathnames.

      If it's just that one specific file, a regex is not necessary and you can use an exact match to exclude it: return if $File::Find::name eq '/var/log/test.out';

      Hope this helps,
      -- Hauke D

      (P.S. I'm assuming that it's obvious that the regex /^\/var\/log\/lastlog/ won't help in excluding a file named test.out and that you just got your examples mixed up.)

        Hi Hauke,

        As suggested, it is good to use an exact match to exclude specific file.

        return if $File::Find::name eq '/var/log/test.out';

        But now if I want to exclude more than one file, can I use an OR condition to the above line. Else for every exclusion I have to write a new exclusion as below:

        return if $File::Find::name eq '/var/log/test.out'; return if $File::Find::name eq '/var/log/new.out';

        Regards, Madparu