Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Created June 25, 2013 17:26
Show Gist options
  • Save ashrithr/5860445 to your computer and use it in GitHub Desktop.
Save ashrithr/5860445 to your computer and use it in GitHub Desktop.
shell function to check if a instance is sshable (can be used for cloud instaces)
function sshable () {
[[ $# -ne 3 ]] && { echo "requires instance, ssh_user, ssh_key arguments"; return; }
instance=$1
ssh_user=$2
ssh_key=$3
command=$(ssh -t -t -o ConnectTimeout=2 -o StrictHostKeyChecking=no -o BatchMode=yes -o UserKnownHostsFile=/dev/null -p 22 -i ${ssh_key} ${ssh_user}@${instance} "echo" &>/dev/null)
until $command; do
echo -e ".\c"
done
echo ""
echo "Instance ${instance} is now shhable"
}
@ashrithr
Copy link
Author

This function can be used in startup scripts and can be used as a command.

Fix: this function hangs indefinitely, add timeout logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment