Interactive script to mount iso images

My laptop's DVD drive is bad, so I prefer copying images of CD/DVDs through a friends computer DVD drive and pasting it in my cd_image folder (a special folder I created for just iso images).
The command I use for copying CD/DVD images is
dd if=/dev/sr0 of=/home/freeman/cd_image/cdname.iso
This command is pretty straight forward,  the dd stands for disk dump, if stands for input file and of stands for output file. I do not have problem with remembering the command. But I often have problem remembering the exact mount options for iso file (which is the cd image file).
So I decided to write a shell script for interactively mounting any iso image in any mount point point (which is often an empty folder).
The following is a step-wise description of the shell creation

STEP 1
I created a special folder in my home folder and named it shell, using the following command
[freeman@freeman ~]$ mkdir shell
I changed directory to the shell subdirectory I just created
[freeman@freeman ~]$ cd shell

STEP 2
I created a new file (named it mountiso) and entered the script in in using vi editor
[freeman@freeman shell]$ vi mountiso
#!/bin/bash
#This shell is for mounting cd images from anywhere to any empty folder
echo -n "Enter the full path of the iso image: "
read image
echo -n "Enter the full path of the mount point, an empty folder: "
read folder
mount -t iso9660 -o loop $image $folder
exit 0

STEP 3
I made the mountiso file executable by changing it's file permissions
[freeman@freeman shell]$ chmod a+x mountiso
I also included the /home/freeman/shell path in the PATH environment variable
[freeman@freeman shell]$ PATH=$PATH:/home/freeman/shell
To make is global, I exported the new PATH
[freeman@freeman shell]$ export PATH

So that was all, to run the new script I just enter mountiso (regardless of my current working directory) and enter both the image location and mount point without bothering about the mount options.

0 comments:

Post a Comment

 
Follow me on Twitter | About me | Terms of Service | Privacy Policy