Ping a host until it answers and then connect. I actually have this in a script that will use the first argument as the host.
while ! ping -W 1 -c 1 <hostname or IP> 2>&1 >/dev/null; do true; done && sleep 15; ssh <user>@<hostname or IP>via The Linux Blog