Mounting USB Drives
Dave Basener
dbasener at aurora.edu
Fri Oct 8 16:07:55 UTC 2004
I posted a script which used kdialog to provide a GUI mount and umount
of USB Drives. I noted that the script had a small bug. I have found
and corrected the bug which was:
If the drive was busy and the script tried to umount it, it failed
(correct) and gave no notification (incorrect).
I have found and corrected that error and, in the case that anyone wants
to use this, I am posting the corrected script. (Mailers may add
unwanted line-feeds, so I have also attached a copy which would be
unaffected by that.)
=============
#!/bin/bash
#
#
# Requirements:
# - WM: Definitely works with KDE, I think it will work with just
# about any X Window Manager, but I am not sure.
#
# - The script assumes the mount point is /mnt/stick. Change the
# MOUNTPOINT definition if you use a different one.
#
# - Requires that the fstab have a line like this:
# /dev/sda1 /mnt/stick vfat user,noauto,umask=0 0 0
#
# - /dev/sda1 might be variable, but on all 3 of my systems that is
# the device
#
# - /mnt/stick - this is entirely up to you, but this must match
# MOUNTPOINT in the script
#
# - the mount options must include "user" and should contain "noauto"
#
# - bash is /usr/bash. If yours is different, change the first line
# of the script to reflect this
#
#
# Description:
# This is a toggle of the mount state of a USB Memory device. It
# uses kdialog as a GUI.
#
# Author: Dave Basener
# dbasener at aurora.edu
# Aurora University
#
# Date: 2004-Oct-8
#
# Yours to copy, use, distribute. Please keep the author information
# intact. Thank you
#
MOUNTPOINT=/mnt/stick
MNTSTATFILE=/tmp/mnt.stat
UMNTSTATFILE=/tmp/umnt.stat
# create and clear the status files
>$MNTSTATFILE
>$UMNTSTATFILE
# try a mount
mount $MOUNTPOINT >$MNTSTATFILE 2>&1
mountResp=$?
# If the mount returns a 32, most probable cause is that the drive
# is already mounted or the drive isn't present, so ...
if [[ $mountResp == 32 ]]
then
# ... try a umount
umount $MOUNTPOINT >$UMNTSTATFILE 2>&1
umountResp=$?
# if neither worked ...
if [[ $umountResp != 0 ]]
then
# indicate the error and get out
kdialog --error "Could not mount nor unmount the memory
stick\n$(cat $MNTSTATFILE)\n$(cat $UMNTSTATFILE)\n"
exit 32
# else, if the umount worked ...
elif [[ $umountResp == 0 ]]
then
# give the all-clear
kdialog --msgbox "Memory unmounted - OK to remove"
fi
# else, if the original mount worked ...
elif [[ $mountResp == 0 ]]
then
# then, it's mounted, but did it mount properly
if [[ -s "$MNTSTATFILE" ]]
then
# there is a message in the stat file - ask what to do
kdialog --warningyesno "Device mounted, but mount
returned:\n$(cat $MNTSTATFILE)\n\nUnmount device?"
diaResp=$?
# if unmount requested, simply recurse
[[ $diaResp -eq 0 ]] && mountStick
else
# It mounted properly - give ACK
kdialog --msgbox "USB Memory mounted - "
fi
else
# some unresolved mount or unmount failure
kdialog --error "Could not mount the memory stick - recognized error
code: $mountResp\n$(cat $MNTSTATFILE)"
fi
========================
--
"... be the change you wish to see in the world." - Gandhi
David Basener http://www.aurora.edu/~dbasener
System Administrator Dave.Basener at aurora.edu
Aurora University 630 844 4889
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mountStick
URL: <http://listman.redhat.com/archives/redhat-list/attachments/20041008/51e1bf96/attachment.ksh>
More information about the redhat-list
mailing list