#!/usr/pubsw/bin/perl -w $ID = q$Id: mtpt,v 1.3 2004/03/11 01:15:58 eagle Exp $; # # mtpt -- Display the mount point of a given AFS volume. # # Written by Neil Crellin # Updated by Russ Allbery # Copyright 1999, 2004 Board of Trustees, Leland Stanford Jr. University # # This program is free software; you may redistribute it and/or modify it # under the same terms as Perl itself. ############################################################################## # Site configuration ############################################################################## # The path to the mount point database. Note that you need to make sure that # all versions of Perl that you use to run this script use the same version of # the Berkeley DB database format. $DB = '/afs/ir/service/afs/data/mountpoints/mountpoints.db'; # You will probably also need to modify the path to Perl at the top of this # script. ############################################################################## # Modules and declarations ############################################################################## require 5.004; use strict; use vars qw($DB $ID); use DB_File (); use Getopt::Long qw(GetOptions); ############################################################################## # Implementation ############################################################################## # Trim extraneous garbage from the path. my $fullpath = $0; $0 =~ s%.*/%%; # Parse command line options. my ($count, $help, $version); Getopt::Long::config ('bundling', 'no_ignore_case'); GetOptions ('count|c' => \$count, 'help|h' => \$help, 'version|v' => \$version) or exit 1; if ($help) { print "Feeding myself to perldoc, please wait....\n"; exec ('perldoc', '-t', $fullpath) or die "Cannot fork: $!\n"; } elsif ($version) { my $version = join (' ', (split (' ', $ID))[1..3]); $version =~ s/,v\b//; $version =~ s/(\S+)$/($1)/; $version =~ tr%/%-%; print $version, "\n"; exit 0; } # Tie the database file. Note that we do not do any locking here even though # we probably should. See the documentation. my %mtpts; tie (%mtpts, 'DB_File', $DB) or die "Unable to read $DB: $!\n"; # If we're just displaying the count, do that and exit. if ($count) { my $total = keys %mtpts; print "$total entries total\n"; exit; } # Walk through the volumes given on the command line and print out the mount # point for each one. for my $volname (@ARGV) { if (exists $mtpts{$volname}) { my ($path) = split (';', $mtpts{$volname}); print "$path\n"; } else { warn "$0: mountpoint for $volname not currently recorded\n"; } } exit 0; __END__ ############################################################################## # Documentation ############################################################################## =head1 NAME mtpt - Display the mount point of a given AFS volume =head1 SYNOPSIS mtpt [B<-hv>] I [I ...] mtpt B<-c> =head1 DESCRIPTION B looks up the provided AFS volumes in a central database of mappings from volume names to mount points and prints the corresponding mount points. It relies on a database that must be maintained whenever new volumes are created or the canonical mount point of a volume is changed. The database format only knows about one mount point per volume, so if a given volume is mounted in multiple places, only one of those locations will be returned (whichever one is recorded in the database). =head1 OPTIONS =over 4 =item B<-c>, B<--count> Don't look up any volumes. Instead, just display the total count of entries in the database. =item B<-h>, B<--help> Print out this documentation (which is done simply by feeding the script to C). =item B<-v>, B<--version> Print out the version of B and exit. =back =head1 EXAMPLES Show the mount point for users.rra: mtpt users.rra Show the mount points for both ls.trip.nntp and ls.trip.news: mtpt ls.trip.nntp ls.trip.news =head1 FILES =over 4 =item F The default location of the mount point database where mount point mappings are looked up. This will use whatever database format that the DB_File that comes with Perl uses. =back =head1 BUGS This program doesn't lock the database. It really should, since it may well return inconsistent results otherwise if someone else is also storing a mount point at the same time. However, in extensive use of this program and related programs, I've never seen that happen. Strange. Nonetheless, at some point locking needs to be added to all of the programs that manipulate the mount point database. The only reason why this has not yet been done is that B can take hours to run and I want to be able to run it without locking all other users out of the database in the meantime. =head1 SEE ALSO loadmtpt(1), cleanmtpts(1) The current version of this program and the B and B utilities are available from their web page at L. =head1 AUTHORS Neil Crellin and Russ Allbery . =head1 COPYRIGHT AND LICENSE Copyright 1999, 2004 Board of Trustees, Leland Stanford Jr. University. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. =cut