Prescript: I have already searched for similar questions but am not able to find a useful answer.
Background: I am using Fedora 64-bit. I want to execute a specific script /bin/usbattached.sh when a usb is attached. I am using Kingston Datatraveller usb stick whose Vendor Id is 0951 and Product Id is 1660 (as found from dmesg and other methods). I have found two udev rules.d directories on my machine, namely /etc/udev/rules.d and /lib/udev/rules.d Since I am not sure which directory to use, I have created my rule file in both of above mentioned directories. Below is my rule
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1660", RUN+="/bin/usbattached.sh"
I have removed ACTION, changed RUN+= to RUN=, written it in new file as well as pre-existing rule files, all without luck.
I use
udevadm control --reload-rules
and
systemctl restart udev.service
to restart udev.
When I run udevadm test on my device, it shows that it does read my rules file but the script doesn't work. Any method to debug it will be highly appreciated.
The script /bin/usbattached.sh sends a notification to the top-right corner of the screen, echo's a message on the screen and appends the current date/time to ~/op file, when run manually. Unfortunately, none of the above mentioned actions are being performed when the usb is attached.
EDIT: Upon adding ´sleep 10´ to my usbattached.sh script, I notice the usb is mounted roughly after 18 seconds. This time changes almost linearly with changing the value from 10 as well. Looks like the script IS being run but I am not having any notification, neither there is a new line appended to the output file
/etc/udev/rules.d
. I've written similar rule, but for other device and it is working.