LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-27-2005, 03:47 PM   #1
OneSeventeen
Member
 
Registered: Oct 2004
Location: Albuquerque, NM
Posts: 41

Rep: Reputation: 16
execute shell script when USB drive plugged in


I would like to execute a shell script when I plug a USB device into my linux box.

I have udev running, and someone mentioned that would be a good place to start, but I don't really know what to do with that info. (the man pages didn't help)

I simply want to plug in a USB drive, and have it execute a shell script, say "/var/myscripts/usb.sh $a"

(where $a is the path to the USB drive, so the shell script could then add files to it, or remove files from it.)
 
Old 10-27-2005, 04:52 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you can do it with udev or hotplug, but just looking now and the udev way does look simpler.... there's a simple example in my 50-udev.rules file:
Code:
# dvb devices
KERNEL=="dvb*", PROGRAM="/etc/udev/scripts/dvb.sh %k", NAME="%c", GROUP="video", MODE="0660"
so this just means that if udev picks up a dvb device (this is a string match on the /dev/ entry that udev automatically creates), it runs what's in the PROGRAM variable, aswell as doing other configuration things. you may well find you already have this in your default rules file or an equivalent.
 
Old 10-28-2005, 10:27 AM   #3
OneSeventeen
Member
 
Registered: Oct 2004
Location: Albuquerque, NM
Posts: 41

Original Poster
Rep: Reputation: 16
I've modified a few of my udev config/rule files to execute a program, but the program never got executed, I didn't know if there were tutorials anywhere on stuff like this, or maybe what lines to specifically add the PROGRAM= to.

Does anyone know if it is possible to add a catchall for removable storage at the end of one of the rules files? Because I'm just not quite sure how to tell if it is a USB storage device before executing my script.
 
  


Reply



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
script to run when flash drive plugged in tuneout Linux - General 1 10-11-2005 12:59 AM
shell script to execute my c executable cranium2004 Programming 2 04-06-2005 05:26 AM
auto execute shell script ykirankumar Linux - Software 3 09-22-2004 07:23 AM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 01:30 PM
shell script how to execute x2000koh Programming 6 07-29-2003 04:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 08:33 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