I am trying to use udev to detect a USB attach event then run a script. There are many examples of this but I can not seem to get it to work.
My script is /usr/bin/
is very plain usbattached.sh
!/bin/bash
echo !Hello World!
mkdir /media/usb_device
mount /dev/sda1 /media/usb_device
My rule in /etc/udev/rules.d is also very simple usbconnected.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="18a5", ATTRS{idProduct}=="0243", RUN+="/bin/usbattached.sh"
I have reset the device many times in hopes udev would update. So far it has not. I also attempted to run a command to refresh the rules with no luck.
udevadm control --reload-rules && udevadm trigger
Is there something wrong with my rule/script?
Plugging my USB into my device I get the output
root@imx6ull14x14evk:/usr/bin# [ 344.348033] usb 1-1: USB disconnect, device number 2
[ 347.572148] usb 1-1: new high-speed USB device number 3 using ci_hdrc
[ 347.796563] usb 1-1: New USB device found, idVendor=18a5, idProduct=0243, bcdDevice= 0.02
[ 347.805120] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 347.820492] usb 1-1: Product: STORE N GO
[ 347.829885] usb 1-1: Manufacturer: Verbatim
[ 347.839204] usb 1-1: SerialNumber: 12050602000042
[ 347.864925] usb-storage 1-1:1.0: USB Mass Storage device detected
Edit: I did give my script executable permissions with chmod +x usbattached.sh
Edit 2: turning on udev debug and watching the journctl. I remove and add my USB device. I see in the log
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: 1-1: /etc/udev/rules.d/usbconnected.rules:1 RUN '/bin/usbattached.sh
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: 1-1: Running command "/bin/usbattached.sh"
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: 1-1: Starting '/bin/usbattached.sh'
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: Successfully forked off '(spawn)' as PID 275.
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: 1-1: Process '/bin/usbattached.sh' failed with exit code 1.
Mar 03 15:44:00 imx6ull14x14evk systemd-udevd[270]: 1-1: Command "/bin/usbattached.sh" returned 1 (error), ignoring.
This means my script is running, but erroring out.