I'm currently working on a project to run an program written in C when a USB device is plugged in. Is this possible with udev rules?
I've currently got it to run a Hello World script when I plug in my device. However, it runs it more than once.
Current path:/etc/udev/rules.d/98-local.rules
Current rule:
SUBSYSTEMS=="usb", ACTION=="add", RUN+="/usr/local/bin/USB.sh"
Script's path: /usr/local/bin/USB.sh
Script:
#!/bin/bash
echo 'Hello World!' >>"/home/<username>/Desktop/udev.out"
exit
I've tried something like this to get the executable to run:
#!/bin/bash
usr/games/blackjack
exit
typing usr/games/blackjack works in the terminal however it doesn't work when the USB device is inserted. However, I know the script is running because I've had them combined in the same file, and the hello world has been created.
I have also tried running the executable from my user account, as follows:
SUBSYSTEMS=="usb", ACTION=='add", RUN+="/bin/su tyler -c '/usr/local/bin/USB.sh'"
However, this doesn't work either.
Is it a problem with device privileges or is it just not possible to run an executable?
*note: I've read the udev rule explanations at http://reactivated.net/writing_udev_rules.html extensively.
). That probably doesn't matter in this case (the scripts will be invoked with the default
/bin/sh`), but you should fix it. – Keith Thompson