Skip to content

Instantly share code, notes, and snippets.

@nbuchwitz
Created March 17, 2023 14:20
Show Gist options
  • Save nbuchwitz/1c8c67311cf701df0e7a7b9629b14abb to your computer and use it in GitHub Desktop.
Save nbuchwitz/1c8c67311cf701df0e7a7b9629b14abb to your computer and use it in GitHub Desktop.
#!/bin/bash
VENDOR_ID=2109
PRODUCT_ID=2817
# find all devices which match our product id
for f in $(grep --include='idProduct' -rlw "$PRODUCT_ID" /sys/bus/usb/devices/usb* 2>/dev/null); do
device=$(dirname $f)
# ensure that vendor id also matches
if [[ $(cat ${device}/idVendor) != $VENDOR_ID ]]; then
continue
fi
# basename of the sysfs path is our device path
# the root port is stripped from the device path (part before the first dash)
devpath=$(basename $device | cut -f 2 -d -)
echo $devpath
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment