Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I would like to learn udev rules. Here is what I do:

victor@X301A1:~$ ls /etc/udev/rules.d/
70-persistent-cd.rules  70-persistent-net.rules  README

Then:

victor@X301A1:~$ sudo gedit /etc/udev/rules.d/01-my-first-udev.rules

My rule:

ACTION=="add", RUN+="echo HELLO ! > /home/victor/udev_test_log.txt"

After saving the file:

 sudo udevadm control --reload-rules

I expected that connecting an USB device would write in the file but nothing happen. Where am I wrong?

share|improve this question
add comment

1 Answer

In RUN you must to put a path to a script. See man udev:

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.

For examle, create a new script, let say hello.sh in /lib/udev with sudo gedit /lib/udev/hello.sh and put next lines inside:

#!/bin/bash

echo HELLO ! > /home/<username>/udev_test_log.txt

Change <username> with your user name. Save the file, close it and make it executable with:

chmod +x /lib/udev/hello.sh

Add a new rule in your /etc/udev/rules.d/01-my-first-udev.rules file like this:

ACTION=="add", RUN+="/lib/udev/hello.sh"
share|improve this answer
    
I tried with my mouse but nothing happens. How can I "debug" this ? –  VictorL May 19 '13 at 18:51
    
@VictorL I edited my answer. Is tested, so it should work. –  Radu Rădeanu May 29 '13 at 7:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.