Possible Duplicate:
How to run a script when a distinct flash-drive is mounted?
When plugging-in my USB HDD, it is mounted automatically, as expected.
After that event, I'd like to automatically mount a specific folder on the usb device. Therefore, I wrote a udev rule containing RUN+="path_to_script
and a script containing mount --bind /media/device/folder mount_directory
.
The problem is that the USB HDD isn't mounted before the script has not finished. Thus, of course it's impossible for the script to work properly: the hdd has to be mounted first, then the script has to be run.
I tried it then with a two script solution. The script executed by udev contains script2 & exit
and the second script contains sleep 10; mount --bind ...
.
However, that doesn't work either. Maybe here it's a problem with permissions? With sudo it also fails. (udev rule is working and script is working when I run it manually (with sudo, of course).).
Can someone help me on this issue? How to run the script correctly AFTER automounting? Or is there another solution?
By the way, it's working when the whole device is also mounted by the script executed by udev: mount /dev/sdb1/ /media/xyz; mount --bind ...
but I preferred another solution, if possible.