Created
May 11, 2010 09:28
-
-
Save sortega/397113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use Getopt::Long; | |
# PUT YOUR MOUNTPOINTS HERE | |
# No trailing slashes | |
use constant MOUNT_POINTS => qw( | |
/mnt | |
); | |
sub parse_mount { | |
my $mounts = {}; | |
for (split /\n/, qx/mount/) { | |
next unless m/((?:\/\S*)+) on ((?:\/\S*)+) type \w+/; | |
my ($device, $mount_point) = ($1, $2); | |
$mount_point =~ s/\/*^//; | |
$mounts->{$mount_point} = $device; | |
} | |
return $mounts; | |
} | |
my $verbose; | |
GetOptions ("verbose" => \$verbose); | |
unless ($verbose) { | |
close STDOUT; | |
open STDOUT, "> /dev/null" or die "Can't open /dev/null"; | |
} | |
for my $mount_point (MOUNT_POINTS) { | |
print "Mount point '$mount_point'\n"; | |
unless (-d $mount_point) { | |
print "\tnot a directory\n"; | |
print "\tUmounting... "; | |
if (system("umount", $mount_point)) { | |
print "KO\n"; | |
print STDERR "Unable to umount $mount_point\n"; | |
next; | |
} else { | |
print "OK\n"; | |
} | |
} | |
my $mounts = parse_mount(); | |
if (defined $mounts->{$mount_point}) { | |
print "\t'$mount_point' OK\n"; | |
next; | |
} | |
print "\tMounting... "; | |
if (system("mount", $mount_point)) { | |
print "Error\n"; | |
print STDERR "Unable to mount $mount_point\n"; | |
} else { | |
print "OK\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment