LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-30-2009, 09:46 AM   #1
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Porteus atma
Posts: 84

Rep: Reputation: 21
Exclamation 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
 
Old 09-30-2009, 02:48 PM   #2
sploot
Member
 
Registered: Sep 2009
Location: Phoenix, AZ
Distribution: Gentoo, Debian, Ubuntu
Posts: 121

Rep: Reputation: 27
Cool

Assuming you have udev:

Code:
File: etc/udev/rules.d/90-hal.rules
 SUBSYSTEM=="block", ACTION=="remove", RUN+="/your/script/goes/here"
Translation: Everytime a block device is removed (This should only be usb disks) run the script entered.

After which, restart HAL.

Last edited by sploot; 09-30-2009 at 02:49 PM. Reason: forgot something..
 
Old 10-01-2009, 10:42 AM   #3
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Porteus atma
Posts: 84

Original Poster
Rep: Reputation: 21
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
 
Old 10-01-2009, 12:08 PM   #4
sploot
Member
 
Registered: Sep 2009
Location: Phoenix, AZ
Distribution: Gentoo, Debian, Ubuntu
Posts: 121

Rep: Reputation: 27
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.
 
Old 10-01-2009, 12:47 PM   #5
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
Quote:
Originally Posted by indiajoe View Post
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.
 
Old 10-03-2009, 08:04 AM   #6
indiajoe
Member
 
Registered: Jan 2009
Location: India
Distribution: Porteus atma
Posts: 84

Original Poster
Rep: Reputation: 21
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
 
Old 10-03-2009, 08:32 AM   #7
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
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
 
Old 10-03-2009, 02:55 PM   #8
speccy
Member
 
Registered: Dec 2008
Location: Portsmouth, UK
Distribution: slackware
Posts: 39

Rep: Reputation: 32
You may be able to use inotifywait.

Code:
#!/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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
free bootable linux os which can remove viruses from pendrives and can run a scan ranadeepak12 Linux - Newbie 1 04-05-2009 11:13 AM
How do I make a simple script and make it run on bootup?? coolblue Programming 5 12-18-2006 09:55 PM
make script run on startup pytheas22 Fedora 1 11-08-2006 10:35 PM
how do i make a script run on login? roseplant SUSE / openSUSE 11 01-24-2006 04:09 PM
Can't make a script run hanasi Linux - Newbie 14 08-27-2005 03:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration