Find USB device's directory /sys/bus/usb/devices/ using idVendor/idProduct

user2718585

I'm trying to make a script that takes the product and vendor id printed by using lsusb, then checking against this ID to find the USB device's directory in /sys/bus/usb/devices.

I initially thought the Bus and Device number printed by lsusb would point to the appropriate folder. For example, if Bus = 002 and Device = 002, the USB's directory would be /usb/devices/2-2. Unfortunately, this turned out to not be the case.

I can manually find the appropriate folder using this command I found in another thread:

for X in /sys/bus/usb/devices/*; do 
    echo "$X"
    cat "$X/idVendor" 2>/dev/null 
    cat "$X/idProduct" 2>/dev/null
    echo
done

However, I need a script that can automate finding this folder.

Radu Rădeanu

If I understood your question, the following script should do the job:

#!/bin/bash

if [ $# -ne 2 ];then
  echo "Usage: `basename $0` idVendor idProduct"
  exit 1
fi


for X in /sys/bus/usb/devices/*; do 
    if [ "$1" == "$(cat "$X/idVendor" 2>/dev/null)" -a "$2" == "$(cat "$X/idProduct" 2>/dev/null)" ]
    then
        echo "$X"
    fi
done

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find USB device's directory /sys/bus/usb/devices/ using idVendor/idProduct

From Dev

Using IOKit to communicate with USB device

From Dev

Find which TTY device connected over USB

From Dev

Find which TTY device connected over USB

From Dev

Find out if a specific device is an USB mass storage

From Dev

Find out which modules are associated with a usb device?

From Dev

Need to find and open a USB serial device on linux

From Dev

Find /dev entry with VID/PID of USB device

From Dev

Applications ignore USB device's incoming data packet while using default HID driver

From Dev

How can I make a udev rule using a “sibling” device's serial number (for USB devices with no unique serials)?

From Dev

How to find sysfs directory for a specific device?

From Dev

Using locate to find a directory

From Dev

Using locate to find a directory

From Dev

Retrieve USB information using pyudev with device name

From Dev

"Forwarding" a USB device's signal through a pair of USB ports on a PC

From Dev

Is it possible to get USB device by USB port using PyUSB

From Dev

How can I open device's directory using Ionic Framework, or ng-cordova?

From Dev

How to Find my App's /data/data using Android Device Monitor's File Explorer

From Dev

How to Find the Device Associated with a Mounted USB Drive in Linux

From Dev

How to find last-added USB device in Windows?

From Dev

Kernel recognizes USB device but then I can't find it in /sys or /dev

From Dev

How to find out UUID of a non-block USB device?

From Java

Find current directory and file's directory

From Dev

Using find to rename a directory into the trash directory

From Dev

Method to find device's camera resolution iOS

From Dev

Connect to the PC's local host through usb cable on android device

From Dev

what's difference between configuration and interface in USB device?

From Dev

What's the command for terminal to find the usb information?

From Dev

Python: Using a filter to find IMEI of a device?

Related Related

  1. 1

    Find USB device's directory /sys/bus/usb/devices/ using idVendor/idProduct

  2. 2

    Using IOKit to communicate with USB device

  3. 3

    Find which TTY device connected over USB

  4. 4

    Find which TTY device connected over USB

  5. 5

    Find out if a specific device is an USB mass storage

  6. 6

    Find out which modules are associated with a usb device?

  7. 7

    Need to find and open a USB serial device on linux

  8. 8

    Find /dev entry with VID/PID of USB device

  9. 9

    Applications ignore USB device's incoming data packet while using default HID driver

  10. 10

    How can I make a udev rule using a “sibling” device's serial number (for USB devices with no unique serials)?

  11. 11

    How to find sysfs directory for a specific device?

  12. 12

    Using locate to find a directory

  13. 13

    Using locate to find a directory

  14. 14

    Retrieve USB information using pyudev with device name

  15. 15

    "Forwarding" a USB device's signal through a pair of USB ports on a PC

  16. 16

    Is it possible to get USB device by USB port using PyUSB

  17. 17

    How can I open device's directory using Ionic Framework, or ng-cordova?

  18. 18

    How to Find my App's /data/data using Android Device Monitor's File Explorer

  19. 19

    How to Find the Device Associated with a Mounted USB Drive in Linux

  20. 20

    How to find last-added USB device in Windows?

  21. 21

    Kernel recognizes USB device but then I can't find it in /sys or /dev

  22. 22

    How to find out UUID of a non-block USB device?

  23. 23

    Find current directory and file's directory

  24. 24

    Using find to rename a directory into the trash directory

  25. 25

    Method to find device's camera resolution iOS

  26. 26

    Connect to the PC's local host through usb cable on android device

  27. 27

    what's difference between configuration and interface in USB device?

  28. 28

    What's the command for terminal to find the usb information?

  29. 29

    Python: Using a filter to find IMEI of a device?

HotTag

Archive