# Check for existence of needed config file and read it SSHTUN_CONFIG=/etc/ssh_tunnel test -r ${SSHTUN_CONFIG} || { echo "${SSHTUN_CONFIG} not existing"; if [ "$1" = "stop" ]; then exit 0; else exit 6; fi; } . /etc/ssh_tunnel ## Extracting into array form, our variables from the config ## file. rm_port=$(REMOTE_PORT) lc_port=$(LOCAL_PORT) dst_host=$(DEST_HOST) dst_port=$(DEST_PORT) ## Get functions from functions library . /etc/init.d/functions ## Starting our ssh_tunneler start() { echo -n "Starting ssh_tunneler:" if [ "${REMOTE}" = "1" ]; then echo -n "setting up ${NO_TUN} remote-forward ssh tunnels." for n in $NO_TUN ; do /usr/bin/ssh -2 -q -f -N -g -R ${rm_port}:${dst_host}:${dst_port} ${REMOTE_HOST} done else echo -n "setting up ${NO_TUN} local-forward ssh tunnels." for n in ${NO_TUN} ; do /usr/bin/ssh -2 -q -f -N -g -L ${lc_port}:${dst_host}:${dst_port} ${REMOTE_HOST} done fi ## Creating a lockfile touch /var/lock/subsys/ssh_tunneler } ## Stopping our ssh_tunneler stop() { echo -n "Stopping ssh_tunneler: " TUN_PID=`ps aux | grep ssh | grep ${REMOTE_HOST} | awk '{print $2}'` /bin/kill $TUN_PID ## Delete the lockfile rm -f /var/lock/subsys/ssh_tunneler echo }