Skip to content

Instantly share code, notes, and snippets.

@jarus
Created December 28, 2012 12:40
Show Gist options
  • Save jarus/4397412 to your computer and use it in GitHub Desktop.
Save jarus/4397412 to your computer and use it in GitHub Desktop.
Simple init script to dig a ssh tunnel
#!/bin/sh
# Simple init script to dig a ssh tunnel
# Author: Christoph Heer <christoph.heer@googlemail.com>
SSH_ARGS="user@remote.host -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