Skip to content

Instantly share code, notes, and snippets.

@charlestang
Created November 20, 2012 13:46
Show Gist options
  • Save charlestang/4118044 to your computer and use it in GitHub Desktop.
Save charlestang/4118044 to your computer and use it in GitHub Desktop.
Build a ssh tunnel in the background and test the port every 30 seconds if tunnel gone away build again.
#!/bin/bash
while true ; do
listen=`netstat -f inet -p tcp -nRa | grep 'LISTEN' | awk '{ print $4 }' | grep 18080`
if [ -z $listen ]; then
nohup ssh -ntt -D 18080 user@domain.com > /dev/null 2>&1 &
fi
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment