#!/bin/bash function open_tty() { if [ -e "/dev/ttyUSB0" ]; then SERIAL="ttyUSB0" elif [ -e "/dev/ttyUSB1" ]; then SERIAL="ttyUSB1" elif [ -e "/dev/ttyUSB2" ]; then SERIAL="ttyUSB2" elif [ -e "/dev/ttyUSB3" ]; then SERIAL="ttyUSB3" fi if [ -z "$SERIAL" ]; then echo "No USB-to-SERIAL detected" else screen /dev/$SERIAL fi } if [ `id -un` != "root" ]; then echo "Enter root password to open tty:" su -c "serialread" exit 0 else open_tty fi