How to make a script run at every mount of pendrives
Hi,
I wanted to run a script everytime a pendrive (or any external storage device) gets mounted. In my slax-atma distro (a derivative from slax) , the pendrives are automatically mounted using HAL. Is there any way I can make my script run each time a pendrive gets mounted? Thanking you in advance, - Joe |
Assuming you have udev:
Code:
File: etc/udev/rules.d/90-hal.rules After which, restart HAL. |
Thanks a lot, just one more doubt..
Hi,
Thanks a lot. I never realised such a vast possibility exists in udev. Now I started studying more about udev. One thing I couldn't figure out is how I can run commands like /usr/bin/kdialog from scripts run from udev. ( I am facing the same problem from crontab). Why is it not working even after I redirect it into >>/dev/pts/0. I know it is possible because I do get graphical interface when the pendrive gets automatically mounted. Thanking you, Joe |
I don't think I understand what you are trying to accomplish in your follow up questions. Can you explain your goal differently, and I will do my best to respond.
|
Quote:
To be able to create a window from a udev rule you must set up a few things in the scripts you run, and I'm not really sure if it would really work. You have to set DISPLAY, to begin with, and probably you will want to use "su" to change to your home user so the GUI process is not running as root, etc. |
Well, Then I shall use a flag..
Hi ,
Thanks again for the solution . It helped a lot.. What I wanted exactly was: How to run scripts which has graphical user interface from udev. Since it is not easy to do that from udev, I understand the best method will be to keep a script running from the startup itself, and keep looking for some Flag file, as a signal to run the script having GUI. And use udev just to create that Flag file when I connect pendrives. To be more specific on what I have to do : I have to run a guide to the contents in each cataloged pendrive, each time a user plugs it into the machine. Am I in the right direction if I do as I mentioned in first paragraph? Thanks a lot for giving me the idea how KDE does that using deamon. - Joe |
Maybe you can add a custom KDE action that will be offered first in the menu when you insert one of those pendrives, provided you can identify somehow all of them. This is just an idea. I found some information here:
http://docs.kde.org/stable/en/kdebas...ons/index.html |
You may be able to use inotifywait.
Code:
#!/bin/bash |
All times are GMT -5. The time now is 03:20 AM. |