LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Cdrom tray status (http://www.linuxquestions.org/questions/linux-hardware-18/cdrom-tray-status-673073/)

freeindy 09-29-2008 09:26 AM

Cdrom tray status
 
Hi,

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.

Thanks

Indy

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?

Indy

ilikejam 09-30-2008 08:40 AM

Hi.

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.

Dave

freeindy 09-30-2008 01:30 PM

ilikejam,

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

Indy


All times are GMT -5. The time now is 05:42 PM.