blob: c097aee6492d101ac1ccc08caf546da6f398bb02 (
plain)
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
|
#!/bin/bash
# Copyright 2021 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script shows mapping of /dev/ttyUSBx links to actual device files in
# the /dev tree. The mapping makes it easy to follow various connected devices
# to their /dev/ttyUSBx links.
TMPF=$(mktemp '/tmp/maptty.XXXXX')
trap 'rm -rf ${TMPF}' EXIT
# Create a text file each line in which maps soft links found in /dev to their
# actual device files, in particular to /dev/ttyUSBx devices.
for f in $(find /dev -type l | grep -Ev '(pci-|char/)'); do
rn="$(readlink -f "${f}")";
echo "${rn}|${f}" >> "${TMPF}"
done
# For all /dev/ttyUSBx devices print all their soft links.
for n in $(ls /dev/ttyUSB* | cut -c12- | sort -n); do
tty="/dev/ttyUSB${n}"
links=( $(awk -F'|' -vtty="${tty}" '{if ($1 == tty) {print $2}}' "${TMPF}" |
sort) )
printf "%-13s %s\n" "${tty}" "${links[0]}"
for link in "${links[@]:1}"; do
printf "%13s %s\n" " " "${link}"
done
done
|