#!/bin/bash set -eu hostname="$(basename "$0")" local_hostname="${hostname}.localnet" public_hostname="p${hostname}" if grep -q "^Host ${hostname}$" ~/.ssh/config; then true elif ping -c1 -t1 "$local_hostname" &> /dev/null; then hostname="$local_hostname" else hostname="$public_hostname" fi while true; do clear echo "Connecting to ${hostname}..." ssh \ -o ServerAliveInterval=1 \ -o ServerAliveCountMax=5 \ -t \ "$@" \ "$hostname" \ "bash --login -c 'screen -dR'" \ && exit 0 echo "Disconnected, waiting..." echo -ne "\\033]0;${hostname}: disconnected!\\007" sleep 1 done