-   Linux - Hardware (
-   -   Cdrom tray status (

freeindy 09-29-2008 09:26 AM

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.



David the H. 09-29-2008 02:06 PM

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.

freeindy 09-30-2008 07:15 AM

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?


ilikejam 09-30-2008 08:40 AM


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.


freeindy 09-30-2008 01:30 PM


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


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