#!/bin/sh default_binding="127.0.0.1:1080" default_host="zyanlu@expample.net" default_pid="$HOME/bin/tunnel.pid" cmd="ssh -NCTqnD $default_binding $default_host" on(){ off $cmd & echo $! > $default_pid echo "$! tunnel opened" } off(){ if [ -f $default_pid ] then pid=`cat $default_pid` process=`ps -p $pid | grep "$cmd"` if [ "$process" ] then kill $pid if [ $? = 0 ] then echo "$pid killed" rm $default_pid else echo "$pid not killed" fi fi fi } stat(){ ps -A | grep "$cmd" | grep -v "grep" } if [ "$1" = "off" ] then off elif [ "$1" = "on" ] then on else stat fi