I am trying to run a script whenever a pendrive is connected to my system.
I followed [this](https://askubuntu.com/questions/284224/autorun-a-script-after-i-plugged-or-unplugged-a-usb-device) and [this](http://ubuntuforums.org/archive/index.php/t-502864.html) 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:

```bsh
#!/bin/bash

env > /tmp/env.out
cp -r /media/*device-name*/* ~/test/

```

I have two questions:

1. 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?
2. 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.