Created
October 4, 2011 14:54
-
-
Save alxrogan/1261835 to your computer and use it in GitHub Desktop.
Script to automate creation of SSH tunnels, with init style invocation
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/sh | |
| # chkconfig: 235 99 00 | |
| # description: Start, Stop, and Restart the SSH Tunnel | |
| case "$1" in | |
| 'start') | |
| ssh -Nf proxy | |
| ps aexf | grep "ssh -Nf proxy" | awk '{print $1}' > $HOME/tmp/tunnel.pid | |
| # pgrep -f proxy > $HOME/tmp/tunnel.pid | |
| ;; | |
| 'stop') | |
| pid=`cat $HOME/tmp/tunnel.pid` | |
| kill $pid | |
| rm -f $HOME/tmp/tunnel.pid | |
| ;; | |
| 'restart') | |
| $0 stop && $0 start | |
| ;; | |
| 'status') | |
| if [ -s $HOME/tmp/tunnel.pid ]; then | |
| pid=`cat $HOME/tmp/tunnel.pid` | |
| if [ "$?" = "0" ]; then | |
| echo "SSH Tunnel (pid $pid) is running" | |
| else | |
| echo "SSH Tunnel is stopped" | |
| fi | |
| else | |
| echo "SSH Tunnel is stopped" | |
| fi | |
| ;; | |
| *) | |
| echo "Usage: $0 { start | stop | restart | status }" | |
| ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment