[SOLVED] How to make a script run at every mount of pendrives
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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
This doesn't quite work as you think it works. KDE is listening and receiving HAL events (that's apart from udev) and it pops a window up to notify you when a new device is inserted. Nothing is launched from a udev rule.
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.
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:
#!/bin/bash
while EVENT=$(inotifywait -q -e create /dev | awk '{print $1$3}'); do
if [[ "$EVENT" =~ 'sd([a-z][0-9])' ]]; then
kdialog --msgbox "$EVENT"
fi
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.