-
-
Save Aeon/a983d512f9634e0af130d62afdd28f3a to your computer and use it in GitHub Desktop.
Keep retrying SSH connection until success (Useful for waiting for VMs to boot)
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
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo '' && echo 'Please also provide server name as in config file...' && | |
exit 1 | |
fi | |
retries=0 | |
repeat=true | |
today=$(date) | |
while "$repeat"; do | |
((retries+=1)) && | |
echo "Try number $retries..." && | |
today=$(date) && | |
ssh "$@" && | |
repeat=false | |
if "$repeat"; then | |
sleep 5 | |
fi | |
done | |
echo "Total number of tries: $retries" | |
echo "Last connection at: $today" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment