-   Linux - Software (
-   -   script command works unless started by udev (

kscott121 12-31-2007 03:42 PM

script command works unless started by udev
I have a set of udev rules to mount and then execute a BASH script when a USB stick is inserted. That works fine (stick is properly mounted and some script commands execute properly) but a find command within the script DOESN'T work if the script is invoked by udev. The find command part does work if I run the script from the command line ?!
The UDEV rules and the find command are below. Any ideas as to what this could be?? I think it may have something to do with the environment setup for the UDEV script but I'm not sure what to do next.

debian4:/opt# cat /etc/udev/rules.d/z10-local.rules
# made by me 12/26/2007
# trying to handle the 1st partition of sda,sdb, or sdc (for now)
ACTION=="add", KERNEL=="sd[a-z][1-9]", SUBSYSTEM=="block", RUN+="/bin/mount /dev/%k"
ACTION=="remove", KERNEL=="sd[a-z][1-9]", SUBSYSTEM=="block", RUN+="/bin/umount /dev/%k"
ACTION=="add", KERNEL=="sd[abc]1", SUBSYSTEM=="block", RUN+="/bin/bash -c '/opt/usbmgmt &'"

FIND Command inside the USBMGMT script::
debian4:/opt# cat usbmgmt | grep find
find /home/user1/cam -depth -name "*.avi" -mmin -240 -execdir cp {} /media/$usbmnt \;

Permissions on the script::
debian4:/opt# ls -l usbmgmt
-rwxr-xr-x 1 root root 5066 2007-12-31 15:12 usbmgmt

harry edwards 12-31-2007 06:52 PM

Is that the entire usbmgmt script? If so maybe you need to specify the full path to find and cp.

Also, what is the dollar ($) sign doing in this section


This will be interpreted as a variable.

kscott121 12-31-2007 11:38 PM

No, the usbmgmt script is longer. But the combination find&copy step is the only line that isn't working (when invoked by the udev rule). When invoked manually from the shell the entire script runs (including the find/copy line) as intended. Even when invoked from the udev rule, the script both reads and writes to the inserted usb stick both before and after the troublesome find/copy line.

The /media/$usbmnt is the mount point of the stick where $usbmnt is a BASH shell variable and gets avalue of either stick1, stick2, or stick3 (corresponding to /dev/sda1, 2 , or 3). The script properly resolves the value for this variable (regardless of which way the script is invoked).

I tryed specifying the full paths to find and cp and see if that was the answer. Thanks for that idea. But alas, same behavior.
I do still think it must have something to do with the udev-established environment for the script (or lack thereof). Any more ideas?

Happy New Year!!

PS I was thinking of using xargs instead of the -exec (or execdir) but I don't know how to put the cp command behind the args statement.
I also thought about breaking it up so find runs (having it store the file list). The the next step would read the filelist and cp it to the stick. Not quite sure how to do this either.
Does either approach sound promising?

All times are GMT -5. The time now is 10:00 PM.