I want to execute a script when I plug in a device in my Linux machine. For example, run xinput
on mouse or a backupscript on a certain drive.
I have seen a lot of articles on this, most recently here and here. But I just can't get it to work.
Here's some simple examples trying to get at least some kind of response.
/etc/udev/rules.d/test.rules
#KERNEL=="sd*", ATTRS{vendor}=="*", ATTRS{model}=="*", ATTRS{serial}=="*", RUN+="/usr/local/bin/test.sh"
#KERNEL=="sd*", ACTION=="add", "SUBSYSTEM=="usb", ATTRS{model}=="My Book 1140 ", ATTRS{serial}=="0841752394756103457194857249", RUN+="/usr/local/bin/test.sh"
#ACTION=="add", "SUBSYSTEM=="usb", RUN+="/usr/local/bin/test.sh"
#KERNEL=="sd*", ACTION=={add}, RUN+="/usr/local/bin/test.sh"
KERNEL=="sd*", RUN+="/usr/local/bin/test.sh"
KERNEL=="*", RUN+="/usr/local/bin/test.sh"
/usr/local/bin/test.sh
#!/usr/bin/env bash
echo touched >> /var/log/test.log
if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
echo ${DEVICE} >> /var/log/test.log
fi
The rules folder is watched by inotify
and should be active immediately. I keep replugging my keyboard, mouse, tablet, memorystick and usb-drive, but nothing. No log file touched.
Now, what would be the most simple way to at least know something is working? It's easier to work from something that's working than from something that's not.
udevadm trigger
or plug a device in to apply the new rule?3.5.0-23-generic
.