LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   UDEV rule not running a command (http://www.linuxquestions.org/questions/linux-software-2/udev-rule-not-running-a-command-823369/)

FizzerJE 08-01-2010 07:42 AM

UDEV rule not running a command
 
Hello

I have a UDEV rule below that maps a symlink from a specific usb device and 'Should' run a command.

Code:

BUS=="usb",SYSFS{serial}=="1111111111111111111111111111",SYMLINK+="myusbstick_%n",RUN+="/usr/local/bin/my_command"
The symlink part is fine but it does not appear to run the command when I plug the device in.

I can run the command "/usr/local/bin/my_command" from the shell fine.

Code:

mount /dev/myusbstick_1 /media/TMPUSB && cryptsetup luksOpen /dev/md5 md5_crypt --key-file=/media/TMPUSB/key && vgscan && vgchange -ay && mount -a && umount /media/TMPUSB
What am I missing. I have tried +x in owner,group and other.

By the way what does UDEV run as, I assumned +x on ROOT as that is the owner should be enough.

berbae 08-02-2010 04:34 AM

I presume that the one line code is your my_command script.
As it is of the form :

command1 && command2 && command3 && ...

if one of the command fails the others will not be executed.
So maybe, when your script is launched by udev, that is what happens.
To know if it is the case and what command fails, you can modify your script like that :
Code:

if ! command1;then
    echo "Error executing command1 whith error $?" > logfilename
    exit
fi
if ! command2;then
    echo "Error executing command2 whith error $?" >> logfilename
    exit
fi
...

Or redirecting the standard output and standard error of the commands :
Code:

echo "Executing command1" > logfilename
if ! command1 &>> logfilename;then
    echo "Error executing command1 whith error $?" >> logfilename
    exit
fi
echo "Executing command2" >> logfilename
if ! command2 &>> logfilename;then
    echo "Error executing command2 whith error $?" >> logfilename
    exit
fi
...

So you will see what happens when udev runs the script.

catkin 08-02-2010 05:59 AM

berbae's advice to get your command to do some logging is good. It might help to post your command here. One possible gotcha is that the $PATH environment variable may not be set to a sane value; try setting it to a sane value or using full paths on commands so $PATH is not used.


All times are GMT -5. The time now is 11:46 PM.