Skip to content

Instantly share code, notes, and snippets.

@everdark
Last active August 29, 2015 14:06
Show Gist options
  • Save everdark/bce9d02405f215185c24 to your computer and use it in GitHub Desktop.
Save everdark/bce9d02405f215185c24 to your computer and use it in GitHub Desktop.
open/close ssh tunnel
#!/bin/bash
[ $# -eq 0 ] && {
echo "Usage: $0 [run|kill]"
exit 0
}
[ "$1" == "run" ] && {
ssh -NfD 8888 <SERVERIP>
echo start ssh tunneling via my server over socks proxy
exit 0
}
[ "$1" == "kill" ] && {
pid_of_existing_tunnel=$(ps -ef | grep "ssh -NfD 8888" | grep -v grep | awk '{print $2}')
if [ "$pid_of_existing_tunnel" != "" ]; then
echo killing process $pid_of_existing_tunnel...
kill $pid_of_existing_tunnel
else
echo No existing tunnel to kill.
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment