Advertisement
metalx1000

Run Script when USB device is plugged in

Apr 2nd, 2020
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.93 KB | None | 0 0
  1. #add new rule
  2. sudo vim /etc/udev/rules.d/01_gamepad.rules
  3. ATTRS{idVendor}=="<vendor ID>", ATTRS{idProduct}=="<product ID>", RUN+="/usr/local/bin/<script to run>"
  4.  
  5. #to get vendor and product id
  6. lsusb
  7.  
  8. #example output
  9. Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  10. Bus 001 Device 008: ID 045e:028e Microsoft Corp. Xbox360 Controller
  11. Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
  12. #example Xbox360 vender=045e product=028e
  13.  
  14. #another way without lsusb
  15. cat /proc/bus/input/devices
  16.  
  17. #example output
  18. I: Bus=0003 Vendor=045e Product=028e Version=0110
  19. N: Name="Microsoft X-Box 360 pad"
  20. P: Phys=usb-0000:00:1a.0-1.5/input0
  21. S: Sysfs=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5/1-1.5:1.0/input/input37
  22. U: Uniq=
  23. H: Handlers=event23 js0
  24. B: PROP=0
  25. B: EV=20000b
  26. B: KEY=7cdb000000000000 0 0 0 0
  27. B: ABS=3003f
  28. B: FF=107030000 0
  29.  
  30. ##after adding rule restart udevadm##
  31. sudo udevadm control --reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement