in reply to How best test that a directory is a mount point of a mounted filesystem?

What's your OS? On my Linux system, I can open and read /proc/mounts to get the same thing mount would tell me.

Replies are listed 'Best First'.
Re^2: How best test that a directory is a mount point of a mounted filesystem?
by Plankton (Vicar) on Jan 27, 2009 at 17:40 UTC
    The OS will most likely be Linux but this could get run a some legacy Solaris systems.

      IIRC solaris uses /etc/mnttab, so you could do something like this:

      my ($mtab, $mounted); $mounted = 0; if($^O eq 'linux') { $mtab = '/etc/mnttab'; } else { $mtab = '/etc/mtab'; } open my $mounts, "<$mtab" or die($!); while(<$mounts>) { if($_ =~ /\S+ (\S+) .*/) { $mounted = 1 if($1 eq '/opt/mymountpoint'); } }

        Sorry, I messed up with the file names. Obviously it needs to be the other way around ;)

        if($^O eq 'linux') { $mtab = '/etc/mtab'; } else { $mtab = '/etc/mnttab'; }

        You could (and probably should) specify solaris for the else-clause, but I'm not sure what $^O yields on Solaris.. Probably just 'solaris'.

        Also don't forget to close the file after all that:

        close $mounts;