1

I can obtain the status of a connected display with: cat /sys/class/drm/card0-HDMI-A-1/status

Is there something analogous for optical drives? I looked around in /sys/ but couldn't find anything that looked like device information for the cdrom (sr0) drive.

I want to write a script that determines if the drive is finished copying, to eject the disc, and then copy the contents once a new disc is inserted into the drive.

2

Minutes after posting this, I found what I was looking for with the help of sudo lshw. On this computer, device information for the CD-ROM/DVD-ROM drive is located in /sys/bus/scsi/devices/0:0:0:0. It looks like I can obtain the device status with cat /sys/bus/scsi/devices/0:0:0:0/device_busy.

Edit: I discovered device_busy alone is not helpful. The busy bit 1 seems to be set only when the disc is actually active (hence the file name). So, when there is a disc in the drive, and it's not busy, cat device_busy returns 0. I would need additional information to have my script correctly eject the disc when it's not busy. It seems difficult to distinguish between the disc in the drive but not active 0, and no disc in the drive 0. I was hoping there would be a file called drive_status that output either ejected or not ejected.

I could grab the exit code of the cp -rf command (or ls when the drive is open), and use both that and the device_busy file to determine when to eject the disc and prompt user to insert a new one. That seems a bit hacky to me, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.