Skip to content

Instantly share code, notes, and snippets.

@andymotta
Created August 23, 2018 23:55
Show Gist options
  • Save andymotta/cafb1e7618d603195a2e9b897c9902f6 to your computer and use it in GitHub Desktop.
Save andymotta/cafb1e7618d603195a2e9b897c9902f6 to your computer and use it in GitHub Desktop.
Wait for ssh to come up in a Bash script
#!/bin/bash
function hurryup () {
until ssh -o ConnectTimeout=2 "$1"@"$2"
do sleep 1
done
}
hurryup root "10.10.0.3"
# -o ConnectTimeout=2 is a slightly hacky way of getting around not responding to network packets,
# reporting ssh: connect to host 10.10.0.3 port 22: Operation timed out until it's responsive.
# Then, when the host responding to network packets, the 1 second sleep with happen in-between
# ssh: connect to host 10.10.0.3 port 22: Connection refused as we wait for ssh to come up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment