Ubuntu – udev rules targeting every USB device

14.04bashudevusb

I'm trying to execute a script whenever a USB is plugged. What I currently have is a demo script in /usr/local/test.sh:

#!/bin/bash

touch /home/kfir/test.txt

I also have a rules file which tries to match ANY USB in /etc/udev/rules.d/100-usb.rules:

ACTION=="add", ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", RUN+="/usr/local/test.sh"

The problem is that the test.txt file is never being created. I also get the following error:

error message

I'm clueless as of what to do now. What I want to achieve is fairly simple, when there is a USB storage device being plugged in, run a simple script (creating a test.txt file in this case).

P.S. the test.sh file is working fine. When I manually ran it, it creates the test.txt file.

Best Answer

Every USB device? Use this simple line in /etc/udev/rules.d/100-usb.rules

ACTION=="add", RUN+="/bin/mkdir /tmp/folder1"

and restart udev

sudo service udev restart

This is expendable

ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", 
Related Question