Skip to content

Instantly share code, notes, and snippets.

@haraldsk
Created June 6, 2015 12:57
Show Gist options
  • Save haraldsk/7b13f4a1095d8a4ab965 to your computer and use it in GitHub Desktop.
Save haraldsk/7b13f4a1095d8a4ab965 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Array of hosts:port Port is the local port to be forwarded as Socks5
SOCKS5_HOSTS=('bastion-1.something.com:1080' 'bastion2-something.com:1081' )
SSH_MONITOR_PORT_BASE=20000
AUTOSSH_PATH='/usr/local/bin'
PATH="${PATH}:${AUTOSSH_PATH}"
for ((i = 0; i < ${#SOCKS5_HOSTS[@]}; i++)); do
host=$(echo ${SOCKS5_HOSTS[$i]} | cut -d ':' -f 1)
port=$(echo ${SOCKS5_HOSTS[$i]} | cut -d ':' -f 2)
monitor_port=$(($SSH_MONITOR_PORT_BASE + $i*2))
echo $(date) Running: autossh -f -M ${monitor_port} -D${port} ${host} -N ssh
autossh -f -M ${monitor_port} -D${port} ${host} -N ssh 2>&1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment