Skip to content

Instantly share code, notes, and snippets.

@poige
Created July 17, 2015 12:04
Show Gist options
  • Select an option

  • Save poige/a87761fff67d4960741e to your computer and use it in GitHub Desktop.

Select an option

Save poige/a87761fff67d4960741e to your computer and use it in GitHub Desktop.

Revisions

  1. poige created this gist Jul 17, 2015.
    30 changes: 30 additions & 0 deletions fwdbak.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/bin/sh

    #
    # Tries to keep SSH-forwarding connection open for port forwarding
    # using given range of local ports.
    #

    UserHost='SPECIFY_USER@HOST.HERE'

    PortMin=20200
    PortMax=20222
    AliveChkSec=17
    AliveChkCnt=3

    Port="$PortMin"
    while :; do
    ssh \
    -o UserKnownHostsFile=/dev/null \
    -o StrictHostKeyChecking=no \
    -o ServerAliveInterval="$AliveChkSec" \
    -o ServerAliveCountMax="$AliveChkCnt" \
    -o ExitOnForwardFailure=yes \
    -C -R"$Port":127.0.0.1:22 \
    "$UserHost"

    Port=$(($Port+1))
    if [ "$Port" -gt "$PortMax" ]; then
    Port="$PortMin"
    fi
    done