Run something when a USB device is connected, not working

I made a script in /etc/udev/rules.d/local.rules

SUBSYSTEM=="usb", SYSFS{idVendor=="b58e"}, SYSFS{idProduct=="9e84"}, ACTION=="add", RUN+="notify-send USB" 

Then I reload udev with

  sudo udevadm control --reload-rules 

I tried to delete everything except the subsystem and run. I tried running '=' instead of '+ =', I'm tired of ATTR instead of SYSFS. I tried "sudo service udev restart" and "sudo reload udev". I disconnect the device, then reconnect it and do not start the action. I tried to rename it to 70-local.rules and change the permissions to + x. I tried to change the "subsystem" to the "bus". I tried setting the "/path/test.sh" parameter, which has the same command.

+4
source share
2 answers

I am not an expert, and this is not an answer, but I found the following steps to determine the appropriate attributes to run:

  • Find the device path using udevadm , lsusb or usb-devices . I usually use lsusb and let the tab end in my shell. In my case, the path is /dev/bus/usb/003/007 .
  • Use udevadm to identify device attributes for writing rules. In my case, I used udevadm info -a --attribute-walk --root --name=/dev/bus/usb/003/007 .
  • Write a rule and make sure it runs. In my case, I just change the owner of the device to the user "stephen", and it is very easy for me to check if it works with ls -l /dev/bus/usb/003/007 . My rule for this case looks like this: SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", OWNER="stephen" . I have a similar rule that puzzled me a bit because the subsystem was expecting ATTRS not ATTR , so I recommend using attributes. The rule in this last case was as follows: `SUBSYSTEM == 'tty', ATTRS {idVendor} ==" 0403 ", ATTRS {idProduct} ==" 6001 ", OWNER =" stephen ".

And of course, man udev always useful. As you said, you should try to determine that your rule is working properly, and it might be best to just make a quick change of ownership on the device, as you did in the first step. Sometimes you may run into problems with bad attributes or symbolic links and

+9
source

he does not start an action

No, it launches an action. The problem is that he does not know where to send the notification, since there is no notification environment when udev starts. You will need to send a DBus message through the system bus and ask the user daemon to catch the message and send a notification instead.

+3
source

All Articles