Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-31-2007, 03:42 PM   #1
Registered: Jul 2003
Location: NC
Distribution: Fedora,Mepis,Debian
Posts: 84

Rep: Reputation: 15
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
Old 12-31-2007, 06:52 PM   #2
harry edwards
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
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.
Old 12-31-2007, 11:38 PM   #3
Registered: Jul 2003
Location: NC
Distribution: Fedora,Mepis,Debian
Posts: 84

Original Poster
Rep: Reputation: 15
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?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
works on command line but not in bash script tara Linux - General 7 02-09-2009 04:57 AM
Command that works on BASH promp but not from a shell script! ChrisScott Linux - General 4 11-27-2006 08:11 PM
bash script works when interactive, endless loop when started via cron dguy Linux - General 5 04-10-2006 12:39 PM
shell script works form command line but not form crontab saifee General 1 10-14-2004 11:27 AM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 03:00 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration