Bekijk de volledige versie : How to run a script on usb device plug?
Hello,
I would like to know where to look for running a script when I plug my USB CSR bluetooth dongle. I can provide the USB id's, and I just have one script to run. Where in the custom firmware do I have to set up a script if it gets a device plugged? Can it be done with a simple config file in the filesystem?
/proc/sys/kernel/hotplug contains the name of the program to be executed during hotplug. you could override this name.
Thanks Oleg,
This is working. I just have to do some greps to run a script depending on the device beeing plugged.
Well, this program gets some args and environment variables set, indicating plug/unplug and vendor/device id, you may want to check them for your device.
Do you know any docs to specify action depending on devices using the hotplug standard program? The one I could find refer to etc/hotplug scripts, and I think this is not the standard linux hotplug program?
hotplug are mostly scripts and dependent on the distro. But the args are the same - they're passed by the kernel itself.
You can examine environment and args using this hotplug replacement:
#!/bin/sh
date >> /tmp/hotplug.log
echo $* >> /tmp/hotplug.log
set >> /tmp/hotplug.log
For reference, here is a script I'm running instead of the hotplug script::
#!/bin/sh
if [ "$PRODUCT" = "a12/1000/1241" ]
then
/tmp/hd/bluetooth/result/bluez
else
if [ "$PRODUCT" = "471/30c/6" ]
then
/tmp/hd/conf/usr/palantir/bin/palantir.exec
else
/sbin/hotplug $1 $2 $3 $4 $5
fi
fi
First id is my CSR bluetooth dongle, second one is my webcam. Otherwise, i run the normal hotplug script.
I inserted a
echo '/tmp/hot' > /proc/sys/kernel/hotplug
in my post-firewall script, after a
cp /tmp/hd/hot /tmp because the script will not run if lauched from anything else than memory.
use Oleg's script in pevious post to get your devices numbers.
because the script will not run if lauched from anything else than memory.
Hm... It should work. In fact it's better to put this script to flashfs and change hotplug in the pre-boot.
Where is the pre-boot script on your firmware?
Sorry, silly question:
it's /usr/local/sbin/pre-boot