Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 09-29-2008, 09:26 AM   #1
Registered: Nov 2002
Posts: 207

Rep: Reputation: 32
Cdrom tray status


Is there anyway I can check status on weather the tray is open or close on my cd-rom drive in bash? The CD shouldn't be mounted once inserted. Only knowledge of that a CD is in the drive is sufficient.


Old 09-29-2008, 02:06 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
One possible way would be to use hal.

If there's a disk in the drive then lshal should show it. If you run "lshal -m" (monitor mode) as you insert the disk, it will show you what entries get added. Then you can use "lshal |grep [one of those lines]" to determine when a disk is present. I believe it can display when a device is mounted as well.

Note that I'm not a hal expert though, so there are probably better ways to go about it.
Old 09-30-2008, 07:15 AM   #3
Registered: Nov 2002
Posts: 207

Original Poster
Rep: Reputation: 32
Hi david,

I only have hal-get-property. But I'm having some trouble using it. I also have to assume that system doen't have lshal utility. Is it still possible?

Old 09-30-2008, 08:40 AM   #4
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

If you've got cdrecord installed (you probably do), you can use:

$ cdrecord -V --inq dev=DEVICE 2>&1 | grep "medium not present"

replace DEVICE with /dev/whatever for the drive. If the grep returns a line (and exits with 0), there's nothing in the drive.

Old 09-30-2008, 01:30 PM   #5
Registered: Nov 2002
Posts: 207

Original Poster
Rep: Reputation: 32

that works. Thanks. It's a shame that there is no simpler check... But one has to be thankfull for whatever one get...



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
How to obtain a interrupt or signal to press the tray key of CDROM? freedomli Linux - Enterprise 0 12-04-2007 02:31 AM
hda status error related to /dev/cdrom on RHEL4 kernel 2.6.9-5smp erinduffy Linux - Kernel 0 11-01-2007 08:32 AM
Lock CDROM tray SmilinJoeFission Linux - Hardware 4 10-19-2007 05:30 PM
tray icons showing on desktop instead of tray cjae Linux - General 3 09-21-2006 06:27 PM
CDROM drive antics - ejects tray on boot lrt2003 General 8 12-14-2004 12:30 AM > Forums > Linux Forums > Linux - Hardware

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

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