On Thu, 26 Oct 2006, Stefan Monnier wrote:
When a USB disk is mounted by gnome-volume-manager, I can unmount it using
nautilus (via right clicking on the disk's icon), but I haven't figured how
to do it from the command line. Any hint?
Here's a perl script I use. Save it somewhere in your PATH (I call it
$HOME/bin/pum), and make it executable (chmod a+x $HOME/bin/pum).
When invoked it generates a list of mounted file-systems in /media/,
asks what to pumount. It will fallback to a lazy umount if necessary.
Term::ReadKey is used to avoid hitting return after your selection
(doubling your productivity!).
apt-get install libterm-readkey-perl
-- Brad
--- START: bin/pum
#! /usr/bin/perl -w
# This is licensed under the Gnu Public License (GPL).
# On Debian systems the text of the license can be found at
# /usr/share/common-licenses/GPL
#
# Initial Author: Brad Sawatzky [EMAIL PROTECTED] (July 2006)
# This relies on Term::ReadKey in the 'libterm-readkey-perl' package.
##
## List auto-mounted filesystems and prompt for pumount ##
##
use strict;
use Term::ReadKey;
use Term::ANSIColor qw(:constants);
$ENV{PATH}=/bin:/usr/bin;
my $DIR=/media;
my @mounts;
my $i=0;
if ($#mounts == -1) {
## FIXME Should probably sanity check results and/or use a perl module here
for (`/bin/ls $DIR`) {
chomp;
my $name = $_;
push @mounts, $DIR/$name;
print RED, [$i]:, RESET, $_\n;
$i++;
}
}
if ($#mounts -1) {
my $choice;
ReadMode('cbreak');
print Unmount: ;
$choice = ReadKey(0);
print $choice\n;
ReadMode('normal');
exit 0 if ($choice !~ /\d/);
if ($choice $#mounts) {
print RED,Invalid selection (,RESET,$choice,RED,)\n,RESET;
exit 1;
}
if (system (/usr/bin/pumount,$mounts[$choice]) != 0) {
print RED, \tpumount failed, attempting lazy punmount\n,RESET;
if (system (/usr/bin/pumount,-l,$mounts[$choice]) != 0) {
print RED,\tlazy punmount failed\n,RESET;
exit 1;
}
}
print BLUE,FS successfully unmounted: ,RESET,$mounts[$choice]\n;
exit 0;
}
print RED,No mounted filesystems found in ,RESET,$DIR\n;
exit 0;
--- END: bin/pum
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]