Skip to content

Instantly share code, notes, and snippets.

@9point6
Last active September 18, 2025 18:01
Show Gist options
  • Save 9point6/ace9c7db75dc694d434d to your computer and use it in GitHub Desktop.
Save 9point6/ace9c7db75dc694d434d to your computer and use it in GitHub Desktop.

Revisions

  1. 9point6 renamed this gist Oct 14, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. 9point6 created this gist Oct 14, 2014.
    24 changes: 24 additions & 0 deletions ssh-retry
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env bash

    # Check we've got command line arguments
    if [ -z "$*" ] ; then
    echo "Need to specify ssh options"
    exit 1
    fi

    # Start trying and retrying
    ((count = 100))
    while [[ $count -ne 0 ]] ; do
    ssh $*
    rc=$?
    if [[ $rc -eq 0 ]] ; then
    ((count = 1))
    fi
    ((count = count - 1))
    done

    # Print a message if we failed
    if [[ $rc -ne 0 ]] ; then
    echo "Could not connect to $* after 100 attempts - stopping."
    fi