I'm playing with Udev Rules on OpenSuse Leap, and I'm trying to run a simple and small script once a USB device is plugged into my system.
However, my script which I added in my keyword "RUN+=" does not run.
These are the steps a follow:
1) I wrote the rule "10_MY_RULES.rules" based on the info given by udevadm info.
KERNEL=="sdf1", SUBSYSTEM=="block", SUBSYSTEMS=="usb", ATTRS{product}=="Flash Drive", ATTRS{manufacturer}=="Samsung",ATTRS{idProduct}=="1000", ATTRS{idVendor}=="090C", RUN="/home/user/bin/script.sh"
My script "script.sh" is the follwoing:
#!/bin/bash; mkdir /home/user/Desktop/CREATE_FOLDER_TEST
2) OpenSuse Leap has several places where it allocates udev rules.
These are the locations:
- /etc/udev/rules.d
- /usr/lib/udev/rules.d
- /run/udev/rules.d
I put my rule in "/run/udev/rules.d" given that when I plug my USB device udev will create an access file under /run.
3) I run the following commands:
- udevadm control --reload-rules
- udevadm trigger
4) Once that was done I also run "udevadm monitor" to see what my system was doing once a peripheral device plugged in, in this case, my USB.
5) I notice no action was being performed, my script was not running, when my flash drive was being added to the system. So I ran the following command to trigger my rule on the specific device
- udevadm test --action=add /path/to/device
I noticed my rule was being read as you can see in the last line of my picture ...
Without any luck, I revised my rule and tinker with it. I add more KERNELS, SUBSYSTEMS,ATTRS,etc
All of the above I ran in two modes as Root and User.
SUBSYSTEMS=="usb"
instead of twoSUBSYSTEMS
?SUBSYSTEMS=="usb"
. For USB redirection we have a rule like this:KERNEL=="[0-9]-[0-9]", SUBSYSTEM=="usb", RUN="/usr/local/bin/usb_share"
If that doesn't work I would reduce the number of checks to a minimum, then start increasing them step by step if the rule still is applied.