The goal is to execute a script when you plug in a USB flash drive.
I have Raspbian Stretch Lite (2017-09-07) in my Raspberry.
The scrit must do the following operations:
1) Create a folder
2) Mount usb drive in a folder
3) Copy file from usb key to a folder
Here is my udev rule:
Code: Select all
# /etc/udev/rules.d/a-myusb.rules
ACTION=="add", KERNEL=="sda1", RUN+="/home/pi/usbScript.sh"
Code: Select all
sudo udevadm control --reload-rules
sudo service udev restart
Code: Select all
#!/bin/sh
# /home/pi/usbScript.sh
nohup /home/pi/usbCopy.sh
exit
Code: Select all
#!/bin/sh
# /home/pi/usbCopy.sh
export PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin
mkdir /home/pi/testUsbCopy
mount /dev/sda1 /home/pi/usb_drive
When I insert my USB flash drive, the folder testUsbCopy is well created, but it doesn't mount the flash drive...
If I run the script by hand, it works:
Code: Select all
pi@raspberry: $ ./usbScript.sh
Thank you in advance