I am trying to run a script whenever a pendrive is connected to my system. I followed this and this question and it is working, but there are still some problems.
This is my udev
rules file:
ACTION=="add", ATTRS{idVendor}=="8564", ATTRS{idProduct}=="1000", RUN+="/usr/local/my_script.sh"
And this is my script:
#!/bin/bash
env > /tmp/env.out
cp -r /media/*device-name*/* ~/test/
I have two questions:
Whenever I plug my USB device in, the script is executed because a file
env.out
is generated in/tmp
, but the data from the USB device are not copied to the test directory.If I run the script manually, it works fine! Why?
How can I make my rules file more general so that it will work for any USB device which is connected without knowing its ID?
My idea behind this is to copy all the data from any connected USB device to my computer automatically when it is connected.