A lot of times I’ll be waiting for a router or other device to come online, and I got sick of the person on the other end of the phone saying “okay, now try it.” So here’s two different scripts that you can use to keep your SSH attempts constant, until it finally works or you CTRL-C out of the script.
The first script is a little more modest, attempting an SSH every minute and stops after four tries / four minutes.
while [ $i -lt 4 ]
This second script is more forceful, attempting a new SSH every 12 seconds. In the first script, the SSH times out by itself after the default timer has been hit, whereas this second script aborts the SSH after 10 seconds of trying, waits 2 more seconds, then attempts another SSH. This script will try 100 times, and will run for 20 minutes. I’ve resorted to using this script exclusively and always have it running when I’m about to hop on a call with someone who’s hooking up a device that I need to get into.
while [ $i -lt 100 ]
ssh -o ConnectTimeout=10 email@example.com