Skip to content

Instantly share code, notes, and snippets.

@robertsinfosec
Created February 8, 2025 20:32
Show Gist options
  • Save robertsinfosec/f46b03fb40d83de54847bc029c927e1b to your computer and use it in GitHub Desktop.
Save robertsinfosec/f46b03fb40d83de54847bc029c927e1b to your computer and use it in GitHub Desktop.

Overview

When you reboot a remote machine with sudo reboot now for example, some machines come back up within :20 seconds. Others, it might take a minute or two. Well, instead of hitting up arrow, Enter and seeing:

ssh: connect to host server.example.com port 22: Connection timed out

Instead of using ssh user@host, this function is sshw user@host, as-in "SSH Wait". You'll see a message like this:

Waiting for SSH on [email protected]..............

And it will print a "." every second until the machine is available again, and then SSH's in.

# Append to your ~/.bashrc to more-elegantly "wait" until an SSH comes back up after a reboot.
sshw() {
host="$1"
shift
echo -n "Waiting for SSH on $host"
while ! ssh -q "$host" exit; do
printf "."
sleep 1
done
echo "" # Print newline once connection is available
ssh "$host" "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment