Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

  • DVD drive tray was closed by the user,

or

  • 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?

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

2 Answers

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.

share|improve this answer
add comment
up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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