Skip to content

Instantly share code, notes, and snippets.

@jnelson
Last active August 29, 2015 13:59
Show Gist options
  • Save jnelson/10923035 to your computer and use it in GitHub Desktop.
Save jnelson/10923035 to your computer and use it in GitHub Desktop.
A horribly fragile script to collate identifying information for ttyUSB devices. Ad hoc testing on Ubuntu. Please don't use this unless you agree to: (1) Hold me blameless and harmless for anything that goes wrong, AND (2) Share colorful stories about what went wrong in a comment.
#!/bin/bash
# Reminder: don't use this.
candidates=`ls /dev | grep ttyUSB`
for targetDevice in $candidates
do
majMinDevNums=`cat /sys/class/tty/$targetDevice/dev`
infoLink=`ls -l /sys/dev/char/$majMinDevNums | awk '{print $NF}' | grep -oP '../../\K.*'`
infoDir=`echo /sys/$infoLink | perl -pe "s|(.*)/[\d-:.]+/$targetDevice/.*|\1|"`
busnum=`cat $infoDir/busnum` || continue
devnum=`cat $infoDir/devnum` || continue
echo $targetDevice $majMinDevNums `lsusb -s $busnum:$devnum`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment