You are not logged in.

#1 2012-06-15 02:11:29

ecognito
Member
Registered: 2009-05-30
Posts: 23

Run script when device is mounted

Hi,

I'm wanting to run a script automatically when a particular USB storage device is mounted. I've looked at the udev rules and utilities from the systemd-tools package, and while that can detect when a device is connected, is does not seem to detect when it is mounted on the file system (two different things). Similarly, using inotifywait to look for a particular file on the USB storage doesn't seem to work as it loses track when the device is unmounted then remounted.

Any ideas?

E.

Offline

#2 2012-06-15 02:31:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Run script when device is mounted

How do you mount the USB?  Couldn't whatever you use to mount also trigger the script?

Also, instead of looking for a file on the USB, can't you use inotify to watch the mountpoint? (eg, watch /media/ directory, when it changes, get the contents and check for your device).

Last edited by Trilby (2012-06-15 02:34:07)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-06-15 03:07:21

ecognito
Member
Registered: 2009-05-30
Posts: 23

Re: Run script when device is mounted

It is usually being mounted by the Calibre ebook manager. It does not have a facility to trigger a script when it mounts a device.

However, the inotifywait on the /media folder works. Not sure why I didn't think of that, I was too focused on watching the /media/device folder I guess. :-)

Thanks.

E.

Offline

Board footer

Powered by FluxBB