I found this little script on internet to get a list of all the usb connected devices. Unfortunaltly this script provides too much information for what I need it to do.
Original script can be found on : https://unix.stackexchange.com/questions/144029/command-to-determine-ports-of-a-device-like-dev-ttyusb0 Pay stackexchange a visit, it is an very informative site.
The script has been slightly altered to fit my needs. I only want to see the TTY interface, if any.
Original code :
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
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"
)
done
As mentioned before, this provides too much information. Information of all connected usb devices. All I had to do is change a filter which exludes “bus/” but now only include “tty”.
This is the altered script I use;
#!/bin/bash
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev)
do
( syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
# I only want to see tty related devices.
#no webcam, no mouse, no keyboards just tty interfaces
[[ "$devname" != "tty"* ]] && exit
# enrich the info with vendor/model information
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z"$ID_SERIAL" ]] && exit
echo -e"/dev/$devname\t-- $ID_SERIAL"
)
done
If a tty device is found you will get an outlut like ;
robert@laptop:~$ lstty
/dev/ttyUSB0 -- FTDI_FT232R_USB_UART_<some identifier>
This script is placed in ~/bin. With the proper rights to execute the script; “chmod +x ~/bin/lstty”. Since bash is defined in the shebang, there is no need to keep the “.sh” suffix. But be carefull when no tty device is found, no output will be given.