Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Simple method for mounting and unmounting disks
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
arand
Apprentice
Apprentice


Joined: 22 Apr 2003
Posts: 215

PostPosted: Sun Jul 27, 2003 6:47 am    Post subject: Simple method for mounting and unmounting disks Reply with quote

Simple method for mounting and unmounting disks

Using this method I was able to create a simple script for mounting and unmounting drives. What this script does when it is excuted it will check mtab for if a certain drive is mounted. If that drive is mounted then the script will unmount or if it is not mounted the script will mount the drive.

Here are the steps for creating this script.
  1. Create the file mntcd.
    Code:
    if grep cdrom /etc/mtab
        then
        umount /mnt/cdrom
        else
        mount /mnt/cdrom
        rox /mnt/cdrom
    fi

  2. Make the file executable.
    Code:
    chmod a+x mntcd

  3. As root copy the file to /bin/

That is it this file can be run from the command line or in my case I made an icon in idesk and had it run this file.

Here are a couple of quick notes.

  • The file can be changed so that it can be used to mount a floppy or another drive, basically replace all instances of cdrom to the appropriate word.
  • Replace rox with your favorite file manager.

If you cannot tell this is my first script that I have written and was happy to see it worked. I would like to add in the future something like a text box that would be displayed when the drive is unmounted, but I do not currently know how to do that.

Please post any questions or suggestions.
Back to top
View user's profile Send private message
Verbal
n00b
n00b


Joined: 17 Feb 2003
Posts: 11
Location: Your Post

PostPosted: Sun Jul 27, 2003 8:37 am    Post subject: Reply with quote

Quote:
I would like to add in the future something like a text box that would be displayed when the drive is unmounted, but I do not currently know how to do that.



Code:

if grep cdrom /etc/mtab
    then
    umount /mnt/cdrom
    echo "#----------------------------------------#"
    echo "#CD rom drive has been unmounted         #"
    echo "#----------------------------------------#"
    else
    mount /mnt/cdrom
    rox /mnt/cdrom
fi



I'm sure you could get more creative with the text. :)

You can also make simple menus using a format like this:

Code:

#!/bin/bash

menu="Mount Unmount Quit"
 select menu in $menu; do

 if [ "$menu" = "Mount" ]; then
 mount /mnt/cdrom
 echo "CDrom mounted in /mnt/cdrom"
 rox /mnt/cdrom

 elif [ "$menu" = "Unmount" ]; then
 umount /mnt/cdrom
 echo "CDrom unmounted from /mnt/cdrom"

 else
 echo "Bye bye!"
 exit
 fi
 done


Get creative with if than statements and you can make tests and all kinds of cool stuff. Sorry if I did too much for you, didn't intend to.
Back to top
View user's profile Send private message
arand
Apprentice
Apprentice


Joined: 22 Apr 2003
Posts: 215

PostPosted: Mon Jul 28, 2003 3:40 am    Post subject: Reply with quote

Quote:
I would like to add in the future something like a text box that would be displayed when the drive is unmounted, but I do not currently know how to do that.


When I said that I was thinking of a text box I was thinking of a gui text box that would tell you that the drive was unmounted.. I do not use this script in the command line, rather I have a button setup in idesk that launches this script.

To give some notification of the unmount being completed I added this line after the umount /mnt/cdrom

Code:
aplay $KDEDIR/share/sounds/KDE_Notify.wav


Again replace this file with your favorite *.wav file. This gives notification of the file being unmounted.

Thank you Verbal for your post, your method is interesting and I will look at it to learn some more about shell programming.

Thanks again for your time,
arand
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum