![]() |
Using UDEV to automatically run a script on optical disc mount?
I'm trying to get a script to run whenever an optical disc is mounted by the system but can't get it to work. I'm running Fedora 12 64bit and the drive is SATA device sr0.
Following online guides, I created a new rule file called '10-my.rules' in '/etc/udev/rules.d' which contains the following: Code:
KERNEL=="sr0", RUN+="/usr/local/bin/myscript"I've gathered some information about my optical drive using the udevadm tool. Here is the result of an info query: Code:
P: /devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0Code:
KERNEL[1266604947.007297] change /devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0 (scsi) |
Have you tried a simpler rule to see if it's the rule or the script that's a problem ?
i.e. Code:
KERNEL=="sr0", NAME="my_optical_disk" |
Hi, thanks for taking time to help me out. Your suggestion of using a simpler rule, I'm afraid, isn't possible since the rule I tested...
Code:
KERNEL=="sr0", RUN+="/usr/local/bin/myscript"Code:
KERNEL=="sr0" |
How do you know your script isn't being run?
Changing to 99-my.rule should ensure that it is, lexically, the last rule processed but you could try changing RUN+= to RUN= to ensure it is not subsequently changed. You can generate (too much!) udev logging (in /var/log files) by changing udev_log in etc/udev/udev.conf to "debug". Maybe "info" will give enough information without going to "debug". |
Quote:
The criteria isn't the problem, the script not running is. Unless you can prove that any rule you supply works, then you cannot say whether the script is even being called. If you read the udev docs you will see that any script does not run in the context of a shell, and is not going to output anything to a terminal through stdout. If you can prove that another simpler rule works, then you can concentrate on the script. I even supplied an example where I didn't change the device, just the action. or not. |
Again, thanks for the help. The script I'm trying to run is very obvious when executed - it's an automatic disc ripper that firstly pops up a dialogue box via zenity for 30 seconds giving an option to exit the script, after that it rips whatever is in the drive, ejects the disc and sets up an encoding cue.
I tried smoker's idea of testing a simple rule Code:
KERNEL=="sr0", NAME="my_optical_disk"I suspect this may be an issue with my script being launch by the system instead of my user account or root. I'll look into more. |
Quote:
|
You're right, Catkin, and that was the problem. Zenity was taking down the script from the get-go since it was the first line in there. However I found a solution by adding an 'export DISPLAY' command to the code.
Code:
export DISPLAY=:0.0; zenity --question --title="Auto Disc Ripper" --text="Allow automatic disc rip?" --timeout=15Code:
SUBSYSTEM=="block", KERNEL=="sr0", ENV{DKD_MEDIA_AVAIABLE}=="1", RUN+="/usr/local/bin/detectdisc" |
Quote:
In case anyone wants to copy this technique, the closing double quote is missing from RUN+="/usr/local/bin/detectdisc. |
| All times are GMT -5. The time now is 04:17 PM. |