udev RUN+= doesn't seem to work
I am making a system to copy all my podcasts over to my memory card (my mp3 player uses a memory card) when it is plugged in. I made a script to do the copying and it works just fine - I can call the script and it does the expected behavior. I made a udev rule to automatically run this script when the card is inserted. I also had the rule make a syslink so that the script could reference the same syslink no matter what device (/dev/sdb1, /sda1, etc) the card ended up on. It matches on the model attribute of the device.
The problem: the rule is making the symlink just fine, but it does not seem to be running the script. I have set the script to chmod 777 for testing purposes - so it is definitely executable by whatever user the udev system is using. The path is correct; I can copy straight from the text file and paste it on the command line, and it works. What could be wrong? The following is the rule: Code:
ATTRS{model}=="Flash*" ACTION=="add", SYMLINK+="memcard", RUN+="/home/shawn/copypodcasts.sh" Code:
echo "preparing to copy podcast directory" |
What fell into my mind when reading your question was if it is enough to chmod the script to 777 as long as it might be in a folder that not everyone has access to. So depending on who "owns" the udev process the /home.... folder might be not accessible. Maybe try to put it in /usr/bin for example and see if that helps.
|
For one thing, get rid of the echo statements. Since udev doesn't have access to your console that could be blocking the program.
|
I tried both suggestions. I also ran chmod after I copied since I'm not sure if cp preserves permissions (is there a way to see permissions on a file?). I also did udevcontrol reload_rules (although I don't think I need to). It still doesn't work.
|
You can look at the permissions on a file with the "ls -l <filename>" command.
The PATH that exists when the command runs depends on the environment of the UDEV daemon. Look for other run+= entries and locate where the called script is. On my SuSE system, there is a script in /lib/udev/. Also make sure that your rule isn't misplaced preventing the device from being mounted. If you get it working, you may want to add another test, such as ID_FS_LABEL={podcast*}. That way you won't accidently delete everything in a flash drive because of the rule. You could redirect any errors output to a logfile. [code] ATTRS{model}=="Flash*" ACTION=="add", SYMLINK+="memcard", RUN+="/lib/udev/copypodcasts.sh 2&>>/tmp/copypodcast.log" |
I suspect that shell scripts may not be executed by udev in this manner. (Just a guess, though) Try running "bash SCRIPTNAME" as the RUN+= command. Also, take note of this excerpt from the manpage:
Quote:
|
Code:
grep mount.sh /etc/udev/rules.d/* I should have reread the manpage. Copying media files would take a long time. Maybe he could send a signal to a daemon which would copy the files. I admit I still have a lot to learn about udev and the hal system, plus how the kde daemon interfaces with hal to do the mounting. |
Oops, I should've remembered the mount.sh bit myself. Quite silly, guess it's getting too late.
|
Yeah - it's copying 800Mb over a usb 1.0 - it's going to take a while. I think I can detach a process by using:
Code:
(somescript.sh &) & Code:
ATTRS{model}=="Flash*" ACTION=="add", SYMLINK+="memcard", RUN+="(/lib/udev/copypodcasts.sh &) &" |
Does anyone know another way to do what I'm trying to do (copy -or sync- files over to a thumb drive automatically when it is inserted)
|
Here is a Linux Journal article on using udev to backup a thumb drive:
http://www.linuxjournal.com/article/9311 It also uses RUN+= in a udev rule. You might want to read his script. After initializing some variables used in the script, this is the first command it runs: # wait for device to settle sleep 10 |
Yep - I tried the wait. No luck. I also put a logger message in at the beginning of the script to see if it was even getting that far; it's not.
|
I just tried that myself and what worked was to put in even the full path to bash, for example
Code:
BUS=="scsi", KERNEL=="sd*", SYSFS{model}=="HD400LD ", SYSFS{vendor}=="SAMSUNG ", NAME="%k", SYMLINK="usbhd-trekstor%n", RUN+="/bin/sh /etc/udev/scripts/logmount.sh" |
Have you tried udevtest with the device path to see what rules are specifically being applied?
|
Another thought: you may want to try removing the whitespace from the model and vendor strings. Per the udev manpage:
Quote:
|
All times are GMT -5. The time now is 09:54 PM. |