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 03-20-2010, 04:30 AM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
i need to constantly check whether a cd is mounted or not using bash


i need to check if a cd is mounted or not using bash ... how is that possible?
 
Old 03-20-2010, 04:45 AM   #2
sd||
Member
 
Registered: Oct 2009
Distribution: Arch Linux
Posts: 89

Rep: Reputation: 18
the question is not clear.
 
Old 03-20-2010, 04:50 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If it is mounted it will show up in df output. If it is loaded but not mounted that would be more difficult to detect.
 
Old 03-20-2010, 05:07 AM   #4
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
ok but you can access the cd only if its mounted right??? even if the cd is loaded
 
Old 03-20-2010, 05:13 AM   #5
sd||
Member
 
Registered: Oct 2009
Distribution: Arch Linux
Posts: 89

Rep: Reputation: 18
use
Quote:
# mount
to check all mounted drives;

use

Quote:
# fdisk -l
to check whether your CD ROM Drive has detected the disk.
 
Old 03-20-2010, 05:34 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,358
Blog Entries: 55

Rep: Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545Reputation: 3545
Quote:
Originally Posted by anurupr View Post
ok but you can access the cd only if its mounted right??? even if the cd is loaded
No, if the CD is loaded then you could 'isoinfo -l dev=/dev/devicename 2>&1| grep -q Unable' and use the "$?" return value. But that wasn't really what you asked for in your OP. (More like 'grep -q cdrom /proc/mounts && echo something').

Last edited by unSpawn; 03-20-2010 at 05:36 AM.
 
1 members found this post helpful.
Old 03-20-2010, 05:46 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
The mount command is indeed the easier way to check, since you can use it (without arguments) as normal user. BTW if your system uses HAL to manage removable devices and if you really need to "constantly" check the cd status, the lshal command may be useful:
Code:
$ lshal -m

Start monitoring devicelist:
-------------------------------------------------
this will interface with the HAL daemon and it will report any changes to mounted device in real time. On the other hand parsing the output of the lshal command (without the -m option) can be useful in scripting, since it gives a lot of information about the drive and the mounted storage media.
 
Old 03-20-2010, 06:09 AM   #8
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
thanx for replying

lshal -m works for monitoring . and i tried modifying the output of lshal using grep .but then i realised i need to make it more generic because i want this script to execute a file on the cd when it is mounted. i used df which shows the what all devices are mounted. here is the output when i use df with the cd mounted


Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda8 18073924 4906836 12248976 29% /
udev 642140 308 641832 1% /dev
none 642140 2632 639508 1% /dev/shm
none 642140 332 641808 1% /var/run
none 642140 0 642140 0% /var/lock
none 642140 0 642140 0% /lib/init/rw
/dev/sda6 39070048 37855272 1214776 97% /media/New Volume
/dev/sda5 1959898 1330254 629644 68% /media/New Volume_
/dev/sdb1 15752188 12568456 3183732 80% /media/ANURUPDT
/dev/sr0 715732 715732 0 100% /media/cdrom0

i tried the same thing on another system with the same cd but in that case instead of showing cdrom0 it showed the actual name i.e the volume label

if i could find some generic way to see if a cd is mounted or not that would be helpful
thanx in advance
 
Old 03-20-2010, 07:40 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
How about hooking into whatever mechanism is mounting the CD -- maybe the udev system? It might be worth looking at the rules in /lib/udev/rules.d/ and /etc/udev/rules.d/
 
  


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
Bash-Check If FS is Already Mounted On Directory fortezza Programming 15 04-27-2013 07:06 PM
How to check whether there's a CD / DVD mounted in C++? g4j31a5 Programming 1 05-29-2007 04:45 AM
Check to see if a drive is mounted joshnya Linux - Newbie 2 11-07-2005 08:56 AM
Install constantly failing media check dneeves Linux - Newbie 7 06-23-2004 12:31 PM
Check if it IS mounted sourceman Linux - General 11 02-27-2002 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 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