I need to automatically copy images off a camera when it is inserted into the USB port. I've written a script to do the copying, and I've found that, by creating a file


with the line

ACTION=="add", KERNEL=="sdg1", RUN+="/path/to/my/script"

I can invoke the script when a USB device (such as the camera) is inserted.

The script is invoked at a time when the disk hasn't been mounted yet. My workaround is to make the script start the copying process in the background after some sleep to give it time for the file system to be mounted, but it would be better to trigger the script right after the file system has been mounted.



The following may work:

Run dbus-monitor before you mount the USB and see what events it generates when the USB is mounted.

Then do something like this How do I run a script on a dbus signal?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.