Skip to content

Instantly share code, notes, and snippets.

@stesh
Created September 20, 2011 23:41
Show Gist options
  • Save stesh/1230746 to your computer and use it in GitHub Desktop.
Save stesh/1230746 to your computer and use it in GitHub Desktop.
Keep a tunnel to a proxy server open on a dodgy shared Internet connection
#!/bin/bash
connect() {
ssh proxyserver -fN
}
disconnect() {
kill -n 9 $(pgrep -f "ssh proxyserver -fN") 2>/dev/null
}
reconnect() {
disconnect
connect
}
is_disconnected() {
nc -z localhost 5000
echo $?
return $?
}
while true; do
is_disconnected && reconnect
sleep 5;
done 1>/dev/null 2>/dev/null &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment