Re: unmounting /media/usbdisk from the command line?



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 <brad+debian@xxxxxxxxxxx> (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 debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: PyQt-x11-gpl-3.16 compile error
    ... License) for Python 2.4.2 on linux2. ... collect2: ld returned 1 exit status ...
    (comp.lang.python)
  • How do I stop my software from getting cracked?
    ... I put all the license check code in a method critical to ... some critical functionality here... ... after school (I graduate high school this year). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: More detail on need AIX guru
    ... If you use the official CD, you can specify -Y option to accept license ... when it came time for the compile to happen tonight ... which you should now enroll. ... > THESE TERMS, SELECT 'EXIT'. ...
    (comp.unix.aix)
  • Re: More detail on need AIX guru
    ... when it came time for the compile to happen ... > have a production license, which you should now enroll. ... > THESE TERMS, SELECT 'EXIT'. ...
    (comp.unix.aix)
  • Unsubscribe
    ... To subscribe or unsubscribe via the World ... Ubuntu magic ... Re: Locale settings (SYNass IT ... Subject: shorten "exit"!? ...
    (Ubuntu)