Skip to content

Instantly share code, notes, and snippets.

@Zejnilovic
Created July 26, 2019 11:13
Show Gist options
  • Save Zejnilovic/85253773e965d5850350170421e49000 to your computer and use it in GitHub Desktop.
Save Zejnilovic/85253773e965d5850350170421e49000 to your computer and use it in GitHub Desktop.
Connect to one of the servers
#!/bin/bash
# Switch this for the list of addresses you want to ssh to
ADDRESS=(127.0.0.1 localhost)
# Switch this for the name of the user you are sshing as
NAME=`echo $USER`
for i in $ADDRESS
do
echo "Trying to connect as $NAME to $i"
if ssh $NAME@$i 2> /dev/null; [ $? -eq 0 ]; then
exit 0
fi
echo "Unable to ssh to $i"
done
echo ""
echo "Ssh Failed"
exit 255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment