SSH Tunnel

#!/bin/bash

# Adapted from the blog "And now it’s all this"
# http://www.leancrew.com/all-this/2008/02/leopard-screen-sharing-over-the-internet/

# Usage: worktunnel localport remoteport user@vncserver

if [ $# = 3 ] ; then
        ssh -L $1:127.0.0.1:$2 -N $3
fi

if [ $# = 4 ]; then
        ssh -L $1:127.0.0.1:$2 -N $3 -p $4
fi

if [ $# -lt 3 ] || [ $# -gt 4 ]; then
        echo "   Usage: worktunnel localport remoteport user@vncserver"
        echo "          worktunnel localport remoteport user@vncserver sshport"
fi