Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,645
Rep:
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.
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:
RUN
Add a program to the list of programs to be executed for a specific
device. This can only be used for very short running tasks. Running
an event process for a long period of time may block all further
events for this or a dependent device. Long running tasks need to
be immediately detached from the event process itself.
I would use a script in ~/bin/ after the device was mounted to do something like what the OP wants to do. However if he can get it to work, great. Part of the problem may be that udev rules aren't the best place for it because udev is used to create devices. Also, running a script like that as root just doesn't feel right.
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.
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
EDIT: That was for just switching on the harddisk and creating the symlink in /dev without mounting it at all. I didn't try the ACTION commands at this point.
Last edited by titopoquito; 05-13-2007 at 03:44 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.