I'm running RHEL6 and I'm trying to write a udev rule that is triggered upon plugging in and removing usb devices. I created a file called 80-usb.rules
in /etc/udev/rules.d/
and I gave it the following contents (so far nothing too specific, just want to test):
ACTION=="add", SUBSYSTEMS=="usb", RUN+="touch /tmp/test"
I saved the file and plugged in a USB drive to test. However, the file /tmp/test
was not created.
I figure my udev rule should match my USB drive, since I can run udevadm info
on the USB drive and at least one of the parent devices has the attribute SUBSYSTEMS=="usb"
.
Why might the udev rule not get triggered?
I tried to run udevadm test --action=add /path/to/device
and it is clear that the .rules
file that I wrote is being processed and that my rules are being matched. Here are a few relevant lines from the output:
parse_file: reading '/etc/udev/rules.d/80-usb.rules' as rules file
udev_rules_apply_to_event: RUN '/bin/touch /tmp/test' /etc/udev/rules.d/80-usb.rules:1
udevadm_test: run: '/bin/touch /tmp/test'
But still, /tmp/test
does not exist. I am so confused. Clearly this rule is being matched and the rules are being applied. So why doesn't the command specified by RUN
execute?
80-usb.rules
file?systemctl restart udev.service
touch
command and settingRUN
to the path to the script?/
, but if you are not sure about that, at least while experimenting you should touch/tmp/udevfile
udev
isn't actually a service on my machine (udev-post
is, but restarting that won't and doesn't help any). Writing to /tmp/ is a good idea though. I don't know why I wasn't writing there before. Brain fart, I guess.udevadm monitor
I can clearly see the add and remove events when I plug/unplug my USB stick. But when I put the udev event attributes found using this method into a udev rule, I cannot get the rule to trigger and the command specified withRUN+="..."
to run. I've even tried manually triggering withudevadm trigger
.