#!/bin/bash -e 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 exec ssh "$hostname" "$@" -t "bash --login -c 'screen -dR'"