Created
July 11, 2025 08:04
-
-
Save woernsn/4c66be295c28ee94aa79c50e59eb0302 to your computer and use it in GitHub Desktop.
get /sys path from lsusb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # usb2sys - find lsusb device in /sys file system | |
| # | |
| # Modified script from https://serverfault.com/a/984649 | |
| usb_devices=($(lsusb | cut -d ' ' -f 6)) | |
| for usb_device in "${usb_devices[@]}" | |
| do | |
| vendor=${usb_device%:*} | |
| product=${usb_device##*:} | |
| sys=/sys/bus/usb/devices/ | |
| cd $sys | |
| for d in *; do | |
| path=$sys$d | |
| if [ -f $path/idProduct ]; then | |
| prod=$( cat $path/idProduct ) | |
| vend=$( cat $path/idVendor ) | |
| if [ $prod = $product -a $vend = $vendor ]; then | |
| echo vend = $vend | |
| echo prod = $prod | |
| echo /sys device is $path | |
| echo | |
| fi | |
| fi | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment