7

I'm trying to create a udev rule to unlock my computer when I connect my phone by USB. I could not find that that rule was being ran and so I tried a much simpler rule. This is the rule (anonymized) :

KERNEL=="sd?1", ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", SYMLINK+="phone", RUN+="touch /home/user/udev.touch"

I know that the rule is running because the link phone -> sdc1 is being created but the file is not being created. Are there security setting that I have to enable for the file to run an external program?

2
  • Have you tried using the full path? /usr/bin/touch
    – arrange
    Oct 10, 2011 at 20:31
  • I just tried it. That is now working. Why does udev not search the path? and does that mean that I will have to have the full path for every command in the script that I want to run as well? Oct 10, 2011 at 20:49

3 Answers 3

6

You must use full path in the RUN key because (man udev)

If no absolute path is given, the program is expected to live in /lib/udev, otherwise the absolute path must be specified. Program name and arguments are separated by spaces. Single quotes can be used to specify arguments with spaces.

Nevertheless the (bash) script itself should behave as normal, that is you don't need to specify the path.

3
  • It seems that only the very simplest of commands works. Scripts don't run either even when the entire path is given Oct 10, 2011 at 22:03
  • 1
    Please post the full script you're trying to run. Be aware that the script is run as root, not as a regular user.
    – arrange
    Oct 11, 2011 at 7:56
  • I found I had a bad path to bash. The script on add works now but the remove rule does not run. I'll ask as a different question. Oct 11, 2011 at 22:41
3

I was having the same problem with udev. I tried almost everything to get to scripts to work when adding and removing devices.

This is the code I made:

ACTION=="add", KERNEL=="sda1", SUBSYSTEMS=="scsi", ATTRS{model}=="AVV207-0        ", SYMLINK+="Lacie", MODE="0666", RUN+="/bin/sh /usr/bin/udev/lacie-add.sh", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sda1", RUN+="/bin/sh /usr/bin/udev/lacie-del.sh", OPTIONS="last_rule"

Adding the OPTIONS="last_rule" parameter did the trick.

3

I've had this issue as well, and I can confirm as of 12.04 you need to specify the full bash path and full bash script for the RUN command to work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .