Created
December 28, 2012 12:40
-
-
Save jarus/4397412 to your computer and use it in GitHub Desktop.
Simple init script to dig a 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 | |
# Simple init script to dig a ssh tunnel | |
# Author: Christoph Heer <[email protected]> | |
SSH_ARGS="[email protected] -p 22 -N -n -L 4950:localhost:4949" | |
PID_FILE="/var/run/remote_host_tunnel.pid" | |
case "$1" in | |
start) | |
if [ -f $PID_FILE ]; then | |
echo "ssh tunnel already exists" | |
else | |
echo "dig ssh tunnel..." | |
start-stop-daemon --start --exec /usr/bin/ssh --background --pidfile=$PID_FILE --make-pidfile -- $SSH_ARGS | |
fi | |
;; | |
stop) | |
echo "break down ssh tunnel..." | |
start-stop-daemon --stop --pidfile=$PID_FILE | |
rm $PID_FILE | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment