Created
November 23, 2012 13:42
-
-
Save andras-tim/4135686 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
#!/bin/bash | |
GLOBAL_PARAMETERS='-N -o ControlMaster=no -o ControlPath=none' | |
BIND_IP=127.0.0.1 | |
REOPEN_SLEEP=5 | |
###### | |
# FUNCTIONS | |
# | |
function supervise_proxy() | |
{ | |
host=$1; shift | |
user=$1; shift | |
port=$1; shift | |
while true; do | |
echo "Starting SOCKS5 proxy... ${host} @ ${BIND_IP}:$port" | |
ssh ${user}@${host} -D ${BIND_IP}:$port ${GLOBAL_PARAMETERS} $@ | |
echo "Proxy ${host} closed. RC=$?" | |
sleep ${REOPEN_SLEEP} | |
done | |
return $? | |
} | |
function ctrl_c () | |
{ | |
if [ ! "${pids}" == '' ]; then | |
kill ${pids} | |
echo | |
fi | |
echo -e '\nABORTED' | |
exit 2 | |
} | |
###### | |
# INIT | |
# | |
export pids= | |
# Set CTRL+C handle | |
trap ctrl_c INT | |
###### | |
# PROXYES | |
# | |
# Template for proxies (required both of 2 lines): | |
#supervise_proxy hostname username local_port [other_ssh_parameters] & | |
#pids="${pids} $!" | |
supervise_proxy foo.bar.com superuser 25222 & | |
pids="${pids} $!" | |
supervise_proxy foo2.bar.com superman 25223 -i ~/my_private_key.pem & | |
pids="${pids} $!" | |
###### | |
# WAITING FOR TERMINATE | |
# | |
while true; | |
do | |
sleep 60 | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment