Created
December 30, 2013 15:19
-
-
Save Karunamon/8183305 to your computer and use it in GitHub Desktop.
SSH tunnel setup script. Source in your profile for awesomeness.
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 | |
function proxtun(){ | |
#Validity check of settings | |
if [ ! -e ~/.proxtun ]; then | |
echo "No proxy user/host set. Please set up a remote machine with SSH" | |
echo "tunneling capability (with keys) and then put that user@host in" | |
echo "~/.proxtun" | |
return 5 | |
fi | |
tunhost=`cat ~/.proxtun` | |
tunpid=`pgrep -f '\-D 9001 '` | |
if [ -z $tunpid ]; then | |
echo "Establishing SSH tunnel" | |
ssh -D 9001 -Nf -o ExitOnForwardFailure=yes $tunhost | |
tunpid=`pgrep -f '\-D 9001 '` | |
if [ -z $tunpid ]; then | |
echo "Error: Unable to set up tunnel." | |
fi | |
else | |
echo "Shutting down SSH tunnel" | |
kill -TERM $tunpid | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment