$ cat vpn2.sh
#!/bin/bash

CHK_CMD=`curl -q --socks5 127.0.0.1:1234 ip.cn | awk '{print $4}'`

if [ "$CHK_CMD" = "Hostigation" ]; then
    echo "ok."
else
    PID=`ps aux | grep 1234 | grep -v grep | awk '{print $2}'`
    if [ "$PID" != "" ]; then
        echo "kill pid: " $PID
        kill -9 $PID
    fi

    date "+%Y-%m-%d %H:%M:%S"
    ssh -C -D *:1234 -f -N -T -n root@vps.lyl.hk
    PID=`ps aux | grep 1234 | grep -v grep | awk '{print $2}'`
    echo "new pid: " $PID
fi