-
-
Save mattberjon/b69df0bcb91aad2a7592a6b5552c3510 to your computer and use it in GitHub Desktop.
Create or kill an SSH tunnel
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/sh | |
# ~/bin/sshr | |
# | |
# modified: 26 Jan 2012 | |
# author: matthieu berjon <matthieu.berjon@wavefield.fr> | |
# licence: WTFPL | |
# | |
# description: create or kill a remote ssh tunnel | |
LOGIN= | |
SERVER= | |
connect_tunnel () { | |
ssh -C2TnN -D 8080 $LOGIN@$SERVER & | |
} | |
kill_tunnel () { | |
KILL=$(ps aux | grep "ssh -C2TnN -D" | head -n 1 | awk '{print $2}') | |
kill -9 $KILL | |
} | |
help () | |
{ | |
cat << EOF | |
Use: $0 [options] [file] | |
Options: | |
-c, --connect connect to the tunnel | |
-k, --kill Stop the tunnel | |
-h, --help Show this help | |
EOF | |
} | |
while getopts ckh OPTION | |
do | |
case $OPTION in | |
c | --connect) | |
connect_tunnel $OPTARG | |
;; | |
k | --kill) | |
kill_tunnel | |
;; | |
h | --help) | |
help | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment