HOW TO : Perl subfunction to unmount a partition in Linux
For my record…here’s a snippet of
perl code that can be called as a sub function to unmount a partition in Linux. The magic is in the line “grep m{$mountPoint}, qx{/bin/mount}”, which essentially lets you check if the partition is already mounted or not.
sub UnMountVolume($)
{
my $mountPoint = $_[0];
print "Unmounting $mountPoint\n";
# Check if the mount point exists
if ( grep m{$mountPoint}, qx{/bin/mount} )
{
#Let's try to unmount it
system("/bin/umount $mountPoint");
}
else
{
print "$mountPoint is not mounted, so didn't have to do anything\n";
}
}
As with any perl code, I am sure there are a tons of ways to do this in a more efficient and “cool” way.
This entry was posted
on Friday, May 22nd, 2009 at 10:18 pm and is filed under Programming, Technology.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.