Created
June 16, 2020 12:13
-
-
Save kharandziuk/736d6f4141141f55bd2a568a230679d0 to your computer and use it in GitHub Desktop.
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 | |
| ip=$1 | |
| maxConnectionAttempts=10 | |
| sleepSeconds=10 | |
| #Waiit until SSH on Bastion server is working | |
| echo "Attempting to ssh" | |
| index=1 | |
| while (( $index <= $maxConnectionAttempts )) | |
| do | |
| status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 $ip echo ok 2>&1) | |
| if [[ $status == ok ]] ; then | |
| exit | |
| elif [[ $status == *"Permission denied"* ]] ; then | |
| exit | |
| else | |
| echo "can't connect, retry..." | |
| fi | |
| sleep $sleepSeconds | |
| ((index+=1)) | |
| done | |
| echo "Can't connect to ssh. Timeout" 1>&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment