0

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 ...

enter image description here

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.

2
  • Have you tried only using SUBSYSTEMS=="usb" instead of two SUBSYSTEMS?
    – slybloty
    Oct 17, 2018 at 19:23
  • I agree with @slybloty, simply use 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.
    – eblock
    Feb 1, 2019 at 9:17

1 Answer 1

1

Have you tried to execute your script.sh manually?

I tried, and got

bash: ./script.sh: /bin/bash;: bad interpreter: No such file or directory

You can't use a semi-colon as a command separator on the #! line of the script. That line is only for specifying the script interpreter and possibly options for it, nothing else.

As it is, your rule seems to fail because your script.sh fails to execute; your udev rules might be just fine. As @eblock commented, you should use the minimum necessary number of checks: if your rule isn't working, you should remove some checks, not add more.

Also note that /run is not persistent, as it is located on a tmpfs filesystem (= essentially a RAM disk). Anything you put in there will be gone after next reboot. As a result, /run/udev/rules.d should be used only for auto-generated rules that are produced by other rules or some other automation.

/usr/lib/udev/rules.d is for the distribution's standard rules. The system administrator is supposed to use /etc/udev/rules.d to supplement or override the standard rules as necessary.

You must log in to answer this question.

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