NSLU2-Linux
view · edit · print · history

OpenSlug.Hotplug History

Hide minor edits - Show changes to markup

January 10, 2006, at 01:34 PM by endecotp -- Note specific to OpenSlug
Changed lines 3-6 from:

This HowTo describes how to run your own script when a device is added or removed. This is often also references as hotplugging.

to:

This HowTo describes how to run your own script when a device is added or removed. This is often also referenced as hotplugging.

This page relates to OpenSlug (at least 2.5). Debian also supports hotplugging in basically the same way, but this page was not written with Debian in mind.

September 06, 2005, at 10:06 AM by effem -- creation
Added lines 1-49:

Run software when a (USB) device is added or removed.

This HowTo describes how to run your own script when a device is added or removed. This is often also references as hotplugging. Note that this has only been tested for USB. If you have info on other buses please add.

If a device is inserted OpenSlug (at least 2.5) executes the program /sbin/hotplug with only one parameter (the bus that has detected the hotplug, e.g. 'usb' or 'pci'). Through environment variables this program gets information on whether this is an addition or removal, which device id etc etc. (for details see below).

/sbin/hotplug will dispatch this to the script or program for the specific bus. For OpenSlug 2.5 and USB it executes /etc/hotplug.d/usb/usb.hotplug. It will also execute /etc/hotplug.d/default/default.hotplug. The latter can be used to deal with unknown devices.

Within usb.hotplug you can basically do whatever you want to. Typically you want to decide on what device was added and take an appropriate action.
A very crude file would look like:
#!/bin/sh
cd /usr/photos
gphoto2 -P
If a digital camera was connected this would copy all pictures from it to the /usr/photos directory (assuming your cam was supported etc).
This is a very basic script as it does not test whether a camera is connected or something else. In real life you probably want to add tests for this.

While creating the script do not forget the #!/bin/sh and don't forget to make the script executable. Of course you can also scribble a (C) program.

Environment variables passed to usb.hotplug

The following environment variables are passed to usb.hotplug. These can be used in your script to decide what action to take. The environment variables were dumped after connecting my digital camera. Note that some of these environment variables (e.g. PATH and HOME) are there always and are not related to USB. I've left them all in for completeness (and because I don't know exactly which ones are from the kernel and passed through the hotplug program).

(:table border=0 width=100% bgcolor=#eeeeff:) (:cell:)

 
ACTION='add'
DEVICE='/proc/bus/usb/003/017'
DEVPATH='/devices/pci0000:00/0000:00:01.1/usb3/3-1/3-1:1.0'
HOME='/'
IFS=' 	
'
INTERFACE='6/1/1'
MODALIAS='usb:v04A9p30B1d0001dc00dsc00dp00ic06isc01ip01'
OPTIND='1'
PATH='/sbin:/bin:/usr/sbin:/usr/bin'
PHYSDEVBUS='usb'
PPID='2949'
PRODUCT='4a9/30b1/1'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD='/'
SEQNUM='219'
SUBSYSTEM='usb'
TYPE='0/0/0'

(:tableend:)

view · edit · print · history · Last edited by endecotp.
Originally by effem.
Page last modified on January 10, 2006, at 01:34 PM