Created
June 6, 2015 12:57
-
-
Save haraldsk/7b13f4a1095d8a4ab965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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