-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindusbdev.sh
executable file
·43 lines (36 loc) · 2.89 KB
/
findusbdev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#findusbdev.sh
if [[ "$1" =~ ^(-h|--help)$ ]]; then
echo "Find which USB devices are associated with which /dev/ nodes
Usage:
$0 [-h|--help] [searchString]
-h | --help Prints this message
searchString Print only /dev/<device> of matching output
With no arguments $0 prints information for all
possible USB device nodes
E.g. $0 \"FTDI_FT232\" - will show /dev/ttyUSBX for a device using
the FTDI FT232 chipset.
"
exit 0
fi
devs=$( (
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev ); do
# ( to launch a subshell here
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && exit
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && exit
echo "/dev/$devname - $ID_SERIAL"
)& # & here is causing all of these queries to run simultaneously
done
# wait then gives a chance for all of the iterations to complete
wait
# output order is random due to multiprocessing so sort results
) | sort )
if [ -z "$1" ]; then
echo "${devs}"
else
echo "${devs}" | grep "$1" | awk '{print $1}'
fi