LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-19-2013, 12:00 AM   #1
Cougar!
LQ Newbie
 
Registered: Apr 2013
Distribution: OpenSuSE
Posts: 10

Rep: Reputation: Disabled
Question Writing a script to manage ISO mounting


Hi, everyone.

I've written a simple script to mount/unmount a certain ISO image.
Code:
#!/bin/bash
if /bin/mount|grep $1; then
/usr/bin/sudo /bin/umount $1
#If the ISO image has already been mounted, unmount it.
else
#If the ISO image has not been mounted, mount it at /media/ISO_Mountpoint
/usr/bin/sudo /bin/mount $1 /media/ISO_MountPoint/
fi
Then I use the script as the default program to open *.ISO files.

However, the script can handle only one ISO image. So here I am, asking how to write a script that can manage mass ISO mounting, just as the following N-S diagram shows.

Moreover, I wonder how can I make a GUI Frontend for the script. I don't want to look at the dreary terminal every time!

I'm longing for your suggestions. Thanks in advance!
Attached Thumbnails
Click image for larger version

Name:	>$ mountiso xxx.iso.png
Views:	18
Size:	67.9 KB
ID:	13462  
 
Old 09-19-2013, 01:55 AM   #2
zeebra
Member
 
Registered: Dec 2011
Distribution: Mageia 3, Debian Wheezy, Maemo, Linux Mint 14.
Posts: 200

Rep: Reputation: Disabled
If you mount them with the loop device I believe they are persistent until unmounted. (I only vaguely remember this from doing this with virtualbox and a game, it was persistently mounted). I am sure you can also make a script for that if I am wrong in the persistency, but as far as I remember, if you have an image on your computerand mount it with a loop device, it will be mounted and automounted until you unmount it.

Perhaps this will help you further:
http://www.linuxquestions.org/questi...t-boot-857763/

In any case, what it sounds like you need to do is assign different loop devices for the images you want to persistently mount and then have them always mount to that loop device.
 
Old 09-19-2013, 02:22 AM   #3
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Cougar! View Post
However, the script can handle only one ISO image. So here I am, asking how to write a script that can manage mass ISO mounting, just as the following N-S diagram shows.
I guess you don't mean the name of the iso. Okay what you got to do is to get a listing of the directory /media/ISO_MOUTNPOINT then sort this then tail the last one if ascending order sort or head the first one if descending order. See if the last number is equal to the max mounts. If bail out with message. If not increment the last number, create dir with this and mount.
The unmount part can be done through grepping mount as you already do or you can have library file where you put pairs of directory and iso file that is mounted there.
 
Old 09-19-2013, 03:36 AM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
loop will manage itself..

you need different mount points

maybe you should base the mountpoint on the iso filename

something like
Code:
#!/bin/bash
ISO=$1
MPBase=/mnt
MP=${ISO%.iso}
MP=${MP/*\/}
MP=${MPBase}/${MP}
RegEx="${MP// /.*}"
grep -q "${RegEx}" /proc/mounts && ( /usr/bin/gksudo -- bash -c "umount \"${ISO}\" ; rmdir \"${MP}\"" ) \
                                || ( /usr/bin/gksudo -- bash -c "mkdir \"${MP}\" ; mount \"${ISO}\" \"${MP}\"" )
 
  


Reply

Tags
question


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] improving a .desktop script for mounting and unmounting ISO files DavidBrenner Linux - Newbie 9 05-13-2013 01:23 AM
When mounting cd-image files the ISO unpacks and iso-inates it self Hevithan Linux - Newbie 6 05-04-2012 09:14 AM
LXer: Mounting ISO Images With Furius ISO Mount On Ubuntu 8.04 Desktop LXer Syndicated Linux News 0 09-26-2008 04:30 PM
Manage automatic mounting/adding to fstab of new devices?? brynjarh Debian 2 02-13-2005 11:40 AM
Manage-ISO image 0.9 problems RadonicMan Linux - Software 1 07-21-2004 10:01 PM


All times are GMT -5. The time now is 10:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration