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:
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
and restart
udev
This is expendable