Created
June 25, 2013 17:26
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function can be used in startup scripts and can be used as a command.
Fix: this function hangs indefinitely, add timeout logic