Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/bin/bash | |
| #port= | |
| #user= | |
| #host= | |
| source .host &> /dev/null || { echo "Please set the host."; exit 1; } | |
| name=$(basename "$0") | |
| tunnel_cmd="ssh -CfNqT -D 1080 ${user}@${host} -p $port" | |
| tunnel_lock=$(pgrep -xf "$tunnel_cmd") | |
| if [[ "$#" = "1" && "$1" = "on" ]] | |
| then | |
| if [ -n "$tunnel_lock" ] | |
| then | |
| echo Tunnel is already on. | |
| exit 1 | |
| else | |
| eval $tunnel_cmd | |
| if [ "$?" != "0" ] | |
| then | |
| echo Failed to turn on tunnel. | |
| exit 1 | |
| fi | |
| echo Tunnel is turned on. | |
| fi | |
| elif [[ "$#" = "1" && "$1" = "off" ]] | |
| then | |
| if [ -n "$tunnel_lock" ] | |
| then | |
| kill $tunnel_lock | |
| echo Tunnel is turned off. | |
| else | |
| echo Tunnel is already off. | |
| exit 1 | |
| fi | |
| else | |
| echo "Usage: $name on | off" | |
| exit 1 | |
| fi | |
| exit 0 |