Linux-Noob Forums
how do I run a script whenever a device is mounted? - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: How Do I? (https://www.linux-noob.com/forums/forum-60.html)
+--- Thread: how do I run a script whenever a device is mounted? (/thread-497.html)



how do I run a script whenever a device is mounted? - tanoloco - 2010-03-17


How do I run a script whenever a device is mounted?

 

The device could be a partition of an internal disk already connected at startup, or an external usb drive to be plugged in.

 

I found a solution using a udev rule but it's working only for usb drive so far.

 

Any suggestion for the internal partition issue instead?

 

Many thanks to all




how do I run a script whenever a device is mounted? - Dungeon-Dave - 2010-03-18


Not sure about internal partitions - these usually get mounted at boot-time (from fstab) so I'm guessing some script running early in the startup framework (if using /etc/init.d/ framework) that checks if the desired partition is mounted then triggers some action would be the way I'd imagine.

 

USB stuff tends to be handled by the event-driven framework (/etc/event.d/) now, since these aren't always present during bootup and often want to be mounted/unmounted during the course of normal operations, hence the udev idea. I imagine some event-trapping routine could be modified to fire off when a specific partition is mounted, but as to how that's done... out of my league, sorry!

 

An alternative approach is to have some security (auditing) utilities watch logfiles for reports of the partition being successfully mounted then fire trigger an action accordingly - the only issue there is having the partitions containing logfiles and utils mounted early (and util running) before other slices come online.

 

What is it you're trying to achieve? Perhaps there could be another route.