Ask Your Question

Automatically copy files from a USB device to local disk

asked 2016-09-12 20:33:17 -0600

geekdave gravatar image

I have a Garmin cycling computer. I want to run an rsync command when I connect it to my machine. I have done a udev script, but that does not execute late enough.

I'm not sure what component does it, but the device gets mounted to /run/media/<username>/GARMIN.

My script rsyncs from this folder to a garmin folder in my documents folder.

What do I need to do to get my script to run after the mount point has been created?


edit retag flag offensive close merge delete


The answer I got so far got me thinking more about what I'm looking for. udev plays the role of identifying the device, and informing something that the device needs to be mounted. What I dont understand is two things: 1) what is the mechanism that udev uses to notify the other service that a mount point is necessary? 2) what is the service that actually does the mounting based upon the notification that it receives?

If I can figure out the answers to those two questions, I can take it from there, and build something that talks to the mounting service and runs my script properly.


geekdave gravatar imagegeekdave ( 2016-09-13 18:05:29 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-09-13 09:31:18 -0600

masteroman gravatar image

What kind of issue you're experiencing while trying to use udev rules? Thing that comes to mind is that it executes the script as soon as device gets connected, not after it is mounted but you could "hack around that" by introducing delay in your script (eg. sleep 30).

Then just call that script in your udev rule:

ACTION=="add", .......  RUN+="/path/to/your/script"
edit flag offensive delete link more


I think a better hack is hacking the dbus, I suspect that this is where the mounting service is informed that a device is ready for mounting...

geekdave gravatar imagegeekdave ( 2016-09-13 18:14:08 -0600 )edit

Theoretically you could acomplish same thing with combination of systemd.mount or automount and your custom systemd service that depends on it.

masteroman gravatar imagemasteroman ( 2016-09-13 23:56:47 -0600 )edit

Question Tools

1 follower


Asked: 2016-09-12 20:33:17 -0600

Seen: 101 times

Last updated: Sep 13 '16