[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Retrieving the signal while plugging a USB key

On Tue, May 05, 2009 at 04:55:05PM +0200, User Debian wrote:
> Hello,
> I would like to know if there is a command I can type with Debian to  
> detect if a USB key has physically connected to the computer.
> My main concern is to get a signal, trace, alarm, etc related to the  
> physical connection between the PC and the USB key. This command can be  
> pooled or else.

You can use udev rules to detect if a USB key has been plugged, you
can even specify a serial number if you care about a specific key.

I use this approach to enable automounting of random USB and Firewire 
devices when they are plugged in. Since it has some fairly long lines,
I am attaching it rather than including the text in-line.



Dave Thayer           | Whenever you read a good book, it's like the 
Denver, Colorado USA  | author is right there, in the room talking to 
dave@thayer-boyle.com | you, which is why I don't like to read 
                      | good books. - Jack Handey "Deep Thoughts"

# use -*- SH -*- mode to turn off wordwrap in jed
#Specifying ENV{ID_FS_USAGE}=="filesystem" doesn't work on add, test inside run cmd
BUS=="usb|ieee1394",SUBSYSTEM=="block",ACTION=="add", run+="/usr/local/bin/removable_drive_handler"

#Specifying BUS doesn't work on remove, but you're unlikely to remove anything besides usb or fW
SUBSYSTEM=="block",ACTION=="remove",ENV{ID_FS_USAGE}=="filesystem", run+="/usr/local/bin/removable_drive_handler"

Reply to: