I know my CD-ROM device (
/dev/sr0) but how can I detect from a script whether the drive is empty or whether there is a disk in it?
You can get information about any block device using the command
If I remove the disk, I don't get any output and exit value is 2. (0 means success. A non-zero value will typically mean something abnormal happen or an error occurred)
Try mounting the device.
Then check the return value $?
If the return is 0, "good" then there was disc present. Else, it will return not good "1" or anything but "0"
So to check silently, I would script it as so.
This is a very simplistic example, but you could do something similar...