Last active
August 29, 2015 14:06
-
-
Save everdark/bce9d02405f215185c24 to your computer and use it in GitHub Desktop.
open/close ssh tunnel
This file contains hidden or 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 | |
[ $# -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