Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

missing automount magic

by osunderdog (Deacon)
on Nov 01, 2005 at 17:19 UTC ( [id://504660]=perlquestion: print w/replies, xml ) Need Help??

osunderdog has asked for the wisdom of the Perl Monks concerning the following question:

I'm having a problems 'seeing' data located on an automount directory. I have tried opendir/closedir as well as glob. Both methods report that the directory is empty, however the os command find will report the data expected.

Of course the short term fix is to use find, however I've found that the options for it very between operating sytems.

Others have suggested that I try to open a file on the target operating system before using opendir/closedir or glob however I haven't had any luck getting that to work.

Here is my sample code, which will run on Linux. The three alternative implementations are located in functions getDirs1, getDirs2 and getDirs3

NOTE: you will need to select a directory that is automounted ($mountpoint) and a regex for a file ($probepoint) that is located on that mountpoint.

Of course, if you run this on a directory that isn't automounted, all three tests should succeed.

If anyone has any suggestions on how to get this to work, please let me know!

use strict; use File::Find; use Carp; use Benchmark; use Test::More tests => 3; my $mountpoint = '/mnt/foofoo'; my $probepoint = qr/^3/; #my $mountpoint = '/tmp'; #my $probepoint = qr/^G/; ok(globMethod(), 'glob Method'); ok(opendirMethod(), 'opendir Method'); ok(osFindMethod(), 'OS Find Method'); sub globMethod { my $dirs = getDirs1($mountpoint); #probe for known directory return(scalar(grep(/$probepoint/, @$dirs)) == 1); } sub opendirMethod { my $dirs = getDirs2($mountpoint); return(scalar(grep(/$probepoint/, @$dirs)) == 1); } sub osFindMethod { my $dirs = getDirs3($mountpoint); return(scalar(grep(/$probepoint/, @$dirs)) == 1); } sub getDirs1 { my $root = shift; my $whackFile = "$root/Volume_Inventory.xml"; my @dirs = grep { $_ !~ /^\./ && -d "$_" } glob("$root/*"); @dirs = map {s|^$root/||; $_;} @dirs; return \@dirs; } sub getDirs2 { my $root = shift; my @dirs; if(not opendir(DH, $root)) { croak "Could not open dir: $root ($!)"; } @dirs = grep { /^[^\.]/ && -d "$root/$_" } readdir(DH); closedir DH; return \@dirs; } sub getDirs3 { my $root = shift; my $cmd = "find $root -maxdepth 1 -follow -type d"; my @dirs = grep {chomp && $_ !~ /^\./ && $_ !~ /^$root$/ && -d $_} `$cmd`; @dirs = map {s|^$root/||; $_;} @dirs; return \@dirs; }

Hazah! I'm Employed!

Replies are listed 'Best First'.
Re: missing automount magic
by robin (Chaplain) on Nov 01, 2005 at 17:50 UTC

    All three methods work just fine, in my tests (Linux 2.4.20-31.9, automount version 3.1.7).

    Have you tried straceing find to see what system calls it's issuing, and comparing that with the failing methods?

Re: missing automount magic
by radiantmatrix (Parson) on Nov 01, 2005 at 19:49 UTC

    This all works fine for me as well. Are you aware that some installations of find cache results?

    Also, the advice to open a file on the automount system before using opendir/readdir is somewhat flawed: on UNIX, opening a directory is opening a file.

    I'm curious: what happens if you manually mount the same volumes to the same paths, thus circumventing automount? If your Perl code succeeds, then it's time to trace and find out the differences. If it fails, you might be dealing with permissions issues (e.g. are you sure your Perl app runs as the same user for whom find works? Have you checked whether perl is setuid as well?).

    Unfortunately, this seems somewhat specific to your system, which makes it very hard to debug via a forum.

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: missing automount magic
by sgifford (Prior) on Nov 01, 2005 at 20:41 UTC
    Something to try: instead of opening $mountpoint, try opening $mountpoint."/.". That will go into the directory, and may help nudge the automounter.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://504660]
Approved by Tomte
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found