path_script=$(cd "$(dirname "$0")"; pwd)
mode=$1
#公网IP
host_proxy=39.108.x.y
#公网相应主机登录名
host_proxy_user_name=abc
#使用密码方式登录,非免密码方式。需要yum install sshpass软件。
#公网主机的用户密码,免密码方式时为空。
host_proxy_user_pwd=
#需要被登录的家庭主机登录名。
local_user_name=abc
ssh_process=`ps -ef | grep "ssh -fN -R 5022"| grep -v grep`
echo $ssh_process
case "$mode" in
'start')
echo "it's ready to start op...."
if test -n "$ssh_process"; then
echo ""
echo "---the ssh reverse proxy info below"
echo "$ssh_process"
echo ""
else
if [ -z "$host_proxy_user_pwd" ]; then
echo "ssh -fN -R 5022:localhost:22 $host_proxy_user_name@$host_proxy"
ssh -fN -R 5022:localhost:22 $host_proxy_user_name@$host_proxy
else
echo "sshpass -p $host_proxy_user_pwd ssh -fN -R 5022:localhost:22 $host_proxy_user_name@$host_proxy"
#如果使用``方式执行,无法执行它,真是奇怪。
sshpass -p $host_proxy_user_pwd ssh -fN -R 5022:localhost:22 $host_proxy_user_name@$host_proxy
fi
fi
echo 'success to start.'
echo "you can test on proxy host:$host_proxy,use the follow commands "
echo 'netstat -nap | grep 5022'
echo "ssh -p 5022 $local_user_name@localhost"
echo "sshpass -p 123 ssh -p 5022 abc@localhost"
;;
'stop')
echo "it's ready to check process..."
if test -n "$ssh_process"; then
echo "had find ssh rever proxy process informaton"
echo "$ssh_process"
echo $ssh_process | awk '{print ($2)}' | xargs kill -9
fi
echo 'success to kill.'
;;
*)
basename=`basename "$0"`
echo "Usage: $basename {start|stop} [ server options ]"
exit 1
;;
esac
exit 1