How to auto-start a program on storage device plug?
I need to auto-mount a storage device AND execute a program passing mount point path to it. How can i do this? I'd like to avoid polling for new storage devices.
I'm looking for something like acpid for ACPI events, but working with storage plug events instead. |
Depending on your distro and packages, I believe that you need to learn about udev rules. There are numerous postings here and elsewhere on the web.
Basically,
In all likelihood, your box already does something if you connect a flash drive or insert media into your DVD drive. You want to accomplish those same things but doing your own thing ... but you might know that much already. Cheers, ~~~ 0;-Dan |
Thank you. I knew there has to be something, just forgot about udev.
|
Here's a udev rule that calls a script
Code:
SUBSYSTEM=="block", ATTR{size}=="976768002", ATTRS{product}=="SimpleDrive mini", ATTRS{serial}=="2512009121800442", ACTION=="add", RUN+="/lib/udev/local/usb_hdd_for_bacula_sync.sh -d add $devpath" Here's what the script does with $devpath. It may not be an optimal solution but it works to mount the device. All the error traps and logging have been removed so the essentials stand out Code:
maj_min="$(cat "/sys$devpath/dev")" For logging, logger -p daemon.info is a good choice but not when you are debugging at the command line when echo is easier! If you want to display graphical messages from the script, yad is a good choice. |
Quote:
What I really want to do is hook in with the built-in notifier feature of my Ubuntu Jaunty. Can someone tell me how to do that? ~~~ 0;-Dan |
Quote:
~~~ 0;-Dan |
Quote:
Quote:
|
All times are GMT -5. The time now is 12:32 AM. |