LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-02-2013, 06:30 AM   #1
Cougar!
LQ Newbie
 
Registered: Apr 2013
Distribution: OpenSuSE
Posts: 10

Rep: Reputation: Disabled
How to write a script which can mount/umount ISO?


Hi,everyone,I'm new to Linux.

I've written a simple script and associated it with ISO files to avoid typing 'sudo mount xxx.iso /mnt/cdrom' over and over again.

Code:
#!/bin/bash
/usr/bin/sudo /bin/mount $1 /mnt/cdrom
However, the script above cannot unmount the ISO image. So I still have to type 'sudo umount xxx.iso' over and over again.

I want to let the script to judge whether the ISO image is already mounted and if so, unmount the image; if not, mount the image. How to do that?
 
Old 09-02-2013, 06:58 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,119

Rep: Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269Reputation: 2269
You can check if an image already mounted by this command:
mount | grep <image-name>
 
1 members found this post helpful.
Old 09-02-2013, 10:55 AM   #3
Cougar!
LQ Newbie
 
Registered: Apr 2013
Distribution: OpenSuSE
Posts: 10

Original Poster
Rep: Reputation: Disabled
I got it. But how to let the script judge it and respond accordingly?
Attached Thumbnails
Click image for larger version

Name:	Unbenannt.jpg
Views:	13
Size:	26.5 KB
ID:	13333  
 
Old 09-02-2013, 11:05 AM   #4
basica
Member
 
Registered: Nov 2011
Location: Australia
Distribution: Arch, LFS
Posts: 166

Rep: Reputation: 37
Something like this I'd imagine:

Code:
if [ mount | grep <image-name> == <image-name> ]
then
      do stuf
fi
 
1 members found this post helpful.
Old 09-02-2013, 11:40 PM   #5
Cougar!
LQ Newbie
 
Registered: Apr 2013
Distribution: OpenSuSE
Posts: 10

Original Poster
Rep: Reputation: Disabled
I made it!

Thanks a lot! I made it!

Code:
#!/bin/bash
if /bin/mount|grep $1; then
/usr/bin/sudo /bin/umount $1
else
/usr/bin/sudo /bin/mount $1 /media/ISO_MountPoint/
fi
 
  


Reply


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
Mount ISO Read/Write Johnsernickle Linux - Software 7 12-03-2016 01:11 AM
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - Newbie 16 09-01-2010 10:07 AM
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - General 2 08-26-2010 04:32 PM
Bash script mount and umount traxy Linux - General 2 03-02-2010 03:56 AM
Mount ISO with read/write access the-yikes Slackware 3 08-06-2007 09:26 PM


All times are GMT -5. The time now is 06:20 AM.

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