Hi everybody, I've been search the web trying to find a solution to this but haven't found one. I want a script to automatically run whenever an optical disc is mounted by the system. It seems like an easy thing to setup but I have yet to get it to work.
Does anyone here have a solution or any ideas?
Thanks!
Automatically Launch Bash Script On Optical Disc Mount?
- flickeringsight
- Posts: 41
- Joined: Fri Nov 06, 2009 3:46 pm
- Location: Ventura, Ca
Automatically Launch Bash Script On Optical Disc Mount?
HDA: 2.6GHz Dual Core, Gigabyte MB, 2GB RAM, Blu-Ray, 320GB+1.0TB+2.0TB+4.0TB, Amahi 8
Re: Automatically Launch Bash Script On Optical Disc Mount?
You should be able to do that by writing your own udev rule, see http://reactivated.net/writing_udev_rul ... ternal-runHi everybody, I've been search the web trying to find a solution to this but haven't found one. I want a script to automatically run whenever an optical disc is mounted by the system. It seems like an easy thing to setup but I have yet to get it to work.
Does anyone here have a solution or any ideas?
Thanks!
- flickeringsight
- Posts: 41
- Joined: Fri Nov 06, 2009 3:46 pm
- Location: Ventura, Ca
Re: Automatically Launch Bash Script On Optical Disc Mount?
Thanks for the help. Unfortunately I've already tried and failed at getting udev rules to work and have read that web page over and again. I must have made four dozen variations without success and am beginning to think udev is just broken.
Here's my last few attempts from the 10-my.rules file I created:
The last line is based on the system-generated "70-persistent-cd.rules" so I figured that should work, but it didn't. You can see I also tried moving my script to different directories and changing the naming a bit. I also tried changing the preceding number on my udev config file from "10-my.rules" to "99-my.rules" in incremental steps and nothing worked. Also I should note that the script I'm trying to execute runs fine from the terminal.
Has anyone else running Fedora 12 gotten a custom udev rule to work?
Here's my last few attempts from the 10-my.rules file I created:
Code: Select all
KERNEL=="sr0", ACTION=="add", RUN+="/usr/local/bin/myscript"
KERNEL=="sr0", RUN+="/usr/local/bin/myscript"
SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="pci-0000:00:1f.2-scsi-1:0:0:0", RUN+="/usr/local/bin/myscript"
KERNEL=="sr0", RUN+="/usr/bin/myscript.sh"
Has anyone else running Fedora 12 gotten a custom udev rule to work?
HDA: 2.6GHz Dual Core, Gigabyte MB, 2GB RAM, Blu-Ray, 320GB+1.0TB+2.0TB+4.0TB, Amahi 8
Re: Automatically Launch Bash Script On Optical Disc Mount?
I did an easy test with my USB.
1. Monitored my /var/log/messages
Found this line when putting my USB in
2. Created this little script: /tmp/test.sh
3. chmod +x /tmp/test.sh
4. vi /etc/udev/rules.d/10-test.rules
5. udevadm control --reload-rules
6. Put my USB in and the file /tmp/test.out was created and contained "Testing!!"
1. Monitored my /var/log/messages
Code: Select all
tail -f /var/log/messages
Code: Select all
Mar 1 09:52:55 fc12 kernel: usb 1-4.3.3: New USB device found, idVendor=2008, idProduct=2018
Code: Select all
#!/bin/bash
echo "Testing!!" >> /tmp/test.out
4. vi /etc/udev/rules.d/10-test.rules
Code: Select all
SUBSYSTEM=="usb", SYSFS{idProduct}=="2018", SYSFS{idVendor}=="2008", RUN+="/tmp/test.sh"
6. Put my USB in and the file /tmp/test.out was created and contained "Testing!!"
- flickeringsight
- Posts: 41
- Joined: Fri Nov 06, 2009 3:46 pm
- Location: Ventura, Ca
Re: Automatically Launch Bash Script On Optical Disc Mount?
Hey jOOc, thanks for the great reply. You helped to remind me to take baby steps when things aren't working.
Short story, I got my script working with the UDEV rule - sweet. I mimicked your test script, which worked, and traced the problem back to an obscure issue with Zenity which I am using to generate a dialog box from my script. Since Zenity wasn't being called from a terminal window it had no point of reference for where to open the dialog box and crashed out the script, so it needed a display explicitly stated. In case anybody needs the Zenity solution, here it is:
HOWEVER! I encountered a second, smaller problem. My script was being launched whenever a disc is mounted AND ejected. By using the udevadm tool command 'udevadm info --query=all --path=/sys/block/sr0' to get information about the drive while a disc was present and not present I was able to figure an addition to my rule that fixed the problem.
The only caveat is that the rule name had to be changed to from "10-my.rule" to "99-my.rule".
Short story, I got my script working with the UDEV rule - sweet. I mimicked your test script, which worked, and traced the problem back to an obscure issue with Zenity which I am using to generate a dialog box from my script. Since Zenity wasn't being called from a terminal window it had no point of reference for where to open the dialog box and crashed out the script, so it needed a display explicitly stated. In case anybody needs the Zenity solution, here it is:
Code: Select all
export DISPLAY=:0.0; zenity --question --title="Auto Disc Ripper" --text="Allow automatic disc rip?" --timeout=15
Code: Select all
SUBSYSTEM=="block", KERNEL=="sr0", ENV{DKD_MEDIA_AVAIABLE}=="1", RUN+="/usr/local/bin/detectdisc"
HDA: 2.6GHz Dual Core, Gigabyte MB, 2GB RAM, Blu-Ray, 320GB+1.0TB+2.0TB+4.0TB, Amahi 8
Who is online
Users browsing this forum: No registered users and 29 guests