a lot of copy/paste brought me again here hoping that this would be helpful for others and also to improve my code
I used the almost perfect code from the answer in this question and added/removed some little stuff
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] || [[ "$devname" == "input/"* ]] || [[ "$devname" == "video0"* ]] || exit
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && exit
busnum="$(udevadm info -a -p $(udevadm info -q path -n /dev/$devname) | awk -F "==" '/busnum/ {gsub("\"","");print $2}' | head -1)"
devnum="$(udevadm info -a -p $(udevadm info -q path -n /dev/$devname) | awk -F "==" '/devnum/ {gsub("\"","");print $2}' | head -1)"
bus_dev=${busnum}:${devnum}
lsusb="$(lsusb -s $bus_dev)"
echo "$lsusb - /dev/$devname"
)
done
output:
Bus 003 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter - /dev/ttyUSB0
NOTE: i don't have any unix experience so if you would like to improve the code please do!
lsusb -t
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M |__ Port 1: Dev 4, If 0, Class=Vendor Specific Class, Driver=ch341, 12M
ttyUSB
device path? That isn't the "port", that's the "Device file path"dmesg -w
is the easy way but check this answer for more options stackoverflow.com/questions/2530096/…