Skip to content

Posts tagged ‘usb’

12
Mai

Howto run a script when a USB device IS Pluged

howto run a script when a USB device is pluged in

This explains how you could run a script made by you (say /usr/local/my_script) when you plug a specific USB device.

1. First run lsusb to identify your device. Example:
$lsusb
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 040a:0576 Kodak Co.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

2. After doing this you know that
- the vendor ID of your device is 040a
- the product ID of your device is 0576

3. Now is time to create your UDEV rule:

Code:
sudo nano /etc/udev/rules.d/85-my_rule.rules

4. And add the text

Code:
ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="040a", SYSFS{idProduct}=="0576", RUN+="/usr/local/my_script"
Explanation:
When the usb_device product identified as 0576 of vendor 040a is added, run /usr/local/my_script
Note that ‘==’ and “!=” are comparators, while = and += are assingments