Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
Created June 16, 2020 12:13
Show Gist options
  • Select an option

  • Save kharandziuk/736d6f4141141f55bd2a568a230679d0 to your computer and use it in GitHub Desktop.

Select an option

Save kharandziuk/736d6f4141141f55bd2a568a230679d0 to your computer and use it in GitHub Desktop.
#!/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