1#!/bin/bash 2# Copyright 2021 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# This script shows mapping of /dev/ttyUSBx links to actual device files in 7# the /dev tree. The mapping makes it easy to follow various connected devices 8# to their /dev/ttyUSBx links. 9 10TMPF=$(mktemp '/tmp/maptty.XXXXX') 11trap 'rm -rf ${TMPF}' EXIT 12 13# Create a text file each line in which maps soft links found in /dev to their 14# actual device files, in particular to /dev/ttyUSBx devices. 15for f in $(find /dev -type l | grep -Ev '(pci-|char/)'); do 16 rn="$(readlink -f "${f}")"; 17 echo "${rn}|${f}" >> "${TMPF}" 18done 19 20# For all /dev/ttyUSBx devices print all their soft links. 21for n in $(ls /dev/ttyUSB* | cut -c12- | sort -n); do 22 tty="/dev/ttyUSB${n}" 23 links=( $(awk -F'|' -vtty="${tty}" '{if ($1 == tty) {print $2}}' "${TMPF}" | 24 sort) ) 25 printf "%-13s %s\n" "${tty}" "${links[0]}" 26 for link in "${links[@]:1}"; do 27 printf "%13s %s\n" " " "${link}" 28 done 29done 30