findDevice.sh 806 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # CLI Parameters
  3. USB_LOCATION="${1}"
  4. if [ -z "${USB_LOCATION}" ]; then
  5. echo "Usage: ${0} USB_LOCATION" 1>&2
  6. exit 1
  7. fi
  8. # Find the serial adapter
  9. TTY_ID="`ioreg -c IOSerialBSDClient | \
  10. grep -C 6 "USB-Serial Controller@${USB_LOCATION}" | \
  11. grep IOSerialBSDClient | \
  12. cut -d '<' -f 2 | \
  13. awk '$1 == "class" {print $4}' | \
  14. cut -d 'x' -f 2 | \
  15. cut -d ',' -f 1`"
  16. if [ -z "${TTY_ID}" ]; then
  17. echo "Unable to find TTY_ID for USB_LOCATION: ${USB_LOCATION}" 1>&2
  18. exit 2
  19. fi
  20. # Find the related device file
  21. DEV="`ioreg -c IOSerialBSDClient | \
  22. grep -C 12 "${TTY_ID}" | \
  23. grep 'IODialinDevice' | \
  24. cut -d '=' -f 2 | \
  25. awk -F '"' '{print $2}' | \
  26. head -n 1`"
  27. if [ -z "${DEV}" ]; then
  28. echo "Unable to find DEV for TTY_ID: ${TTY_ID}" 1>&2
  29. exit 2
  30. fi
  31. # Display and exit
  32. echo "${DEV}"
  33. exit 0