Help with udev rule not working

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read how to get help
Post Reply
Level 1
Level 1
Posts: 3
Joined: Sun Nov 29, 2015 5:25 pm

Help with udev rule not working

Post by jasen »

Forgive if I'm a bit rusty, haven't used a Linux distro in a few years.
I'm trying to create a udev rule to fire a script when any drive is mounted. Technically, the target will be USB drives being plugged in.
So I created my file under /etc/udev/rules.d/, and in it I have:

ACTION=="add", SUBSYSTEM=="block", RUN+="/home/jasen/"

So, by my thinking, any block device added to the system should trigger this. (I ran 'udevadm monitor --property' in a terminal while inserting a USB drive to watch what devices it recorded, and that was one of the last couple) The script it's pointing at does nothing more than 'date > sawusb' to record a timestamp as proof that it was triggered.
So even after running 'udevadm control --reload', then 'service udev restart', and rebooting, inserting a USB drive never triggers my script.
Thinking maybe it just doesn't like the subsystem "block", I also tried a rule using:
ACTION=="add", SUBSYSTEM=="usb", KERNEL=="sdb*"
following examples from others online. Still nothing.

Am I making some mistake in crafting the rule, or something else?
(this is 17.2 Cinnamon, if it makes a difference)
Level 2
Level 2
Posts: 72
Joined: Sat Nov 14, 2015 9:50 am

Re: Help with udev rule not working

Post by tolkien »

I realize this thread is somewhat old, but no one has responded to it. So if you still need it, try this:
Call the bash interpreter in the udev rule file:
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/bash /home/jasen/"
And also write out the full path of the date output file in your script:
date > /home/jasen/sawusb
Post Reply

Return to “Other topics”