In my linux bash script I want to wait for one of the following events:

  • DVD drive tray was closed by the user,


  • writeable DVD was inserted to the drive.

Unfortunately all the commands to check the media in drive first close the tray and I don't want to do that - it should stay open and wait for DVD being inserted by the user.

Could you please advice me how to do that?

  • You didn't mention the operating system at all which makes it impossible to answer this question.
    – Istvan
    Dec 24, 2010 at 12:44
  • The tag says "Linux".
    – Andrew M.
    Dec 24, 2010 at 13:33
  • clarified in question text.
    – Arek
    Dec 27, 2010 at 8:10

2 Answers 2


This is highly platform specific. What you might need to do is either (a) parse /var/log/messages for ascpi events, or (b) depending on platform, monitor DBUS for changes. When you open and close the tray, events are generated that can be detected, but this may be more trouble than its worth. Regardless, the DBUS method will work for popular distros such as Fedora and Ubuntu out of the box.

Good luck; I'm definitely interested in seeing how this turns out!

EDIT: Found a good blog post that does this from Python, but since DBUS is designed to be application agnostic, you can use some of the values from the page.


I managed to solve the problem using:

udisks --show-info $1 |grep -c "blank: *1"

It checks if the media inserted is blank, without closing the tray.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .