LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create script to mount / unmount drive (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-script-to-mount-unmount-drive-343856/)

rollo 07-16-2005 07:59 PM

How to create script to mount / unmount drive
 
I would like to make mounting and unmounting my USB Zip drive just a bit less baroque.

I've put an entry in /etc/fstab, but still to mount the thing requires opening a console and typing the 'mount /media/zip' 'umount /media/zip' etc

What's the easiest way to automate this? A script I guess, but I can't find anything provided by Suse.

Apparently something like

Code:

!/bin/bash
mount /media/zip

would do the job.

1. So - newbie question, this - how do you get the text file recognised as a script for clicking on in KDE?

2. Also, I came across this script, which apparently works for mounting and unmounting. Does it look possible for a USB device?

Code:

#!/bin/bash
affichage=`/bin/mount | grep /dev/hdd4`
if test -z $affichage
then
mount /dev/hdd4
else
umount /dev/hdd4
exit

Thanks for advice.

nevarlen 07-16-2005 08:48 PM

yes, the script would work just fine, just make sure that "/dev/hdd4" is your usb device's actual mount-point, otherwise you'd be mount/unmounting other devices.

Kahless 07-16-2005 09:27 PM

and chmod+x the script so the system knows its allowed to run it


dont forget the # in #!/bin/bash

rollo 07-16-2005 09:42 PM

Well it didn't seem to work, but that's okay as I found a much better solution - a 'script' provided by KDE in the form of the app KDiskFree, which I didn't know existed.

Let's face it, you shouldn't really need to write scripts to mount a drive anyway...

Thanks for the help anyway, I did learn something for the future occasion when it really is necessary. :)

Franklin 07-16-2005 09:48 PM

You could always just make a desktop icon which mounts the drive when you click it.

Right-click the desktop
Create New
Link to device
Choose fstab entry from dropdown.

whovian 07-16-2005 10:08 PM

^ is there a way to do that in fedora?

Franklin 07-17-2005 08:04 AM

Since the OP was using KDE, I did not specify in my reply that my suggestion was for KDE.

In FC4 (or any distro) the solution is dependent on the window manager or desktop environment.
In other words, if it works it should work in all distros.

That being said, FC4 uses Gnome by default (I believe) and this is a bit different. One method would be to do what was suggested above and use the disk mounter applet which will park itself on the gnome-panel. I am far more familiar with KDE than Gnome. XFCE4 seems much easier in this regard as well.

The zip drive has been troublesome for some people using 2.6.X kernels in some distros in that if a disk is not in the drive (mine is an internal ide drive - paralell may differ) at boot, a device node is not created. I have seen fixes for this described in many places which involve creating a permanent device node for the drive. This appears to be a simple process, but I use 2.4.31 still and cannot tell you from experience as I do not have the problem (yet).

HTH

Boow 07-17-2005 11:01 AM

You could try dbus hal if they have that in suse. I installed that in slackware it worked except it caused cd ripping to take forever. I think mabye a kernel or configuration problem.

Simon Bridge 08-01-2005 05:39 AM

For FC4 - there is a user mount tool.
Launchers can be created the same way in GNOME as in KDE.
The zip drive must be mentioned in /etc/fstab in order to be mounted by any user. However - FC4 is very good at autodetecting removeable media. I have not the zip drive, but my usb memory stick is detected and an icon appears on the desktop... I barely have to twitch.


All times are GMT -5. The time now is 06:35 PM.