Automatically Recover SSH Connection

TurnToJPG -->

Thanks for the Great File Wall, my ssh connection to my vps is not stable, so I use following scripts for automatically maintain the ssh conneciton, once the connection down, it will restart immediately.

$ vim 

while [ '' == '' ]
        # Use ssh -R for reverse ssh
        ssh_d_process_num=`ps aux|grep -E 'ssh -NfR' |grep -v grep |wc -l`
        if [ "$ssh_d_process_num" == "0" ]; then
                # Automatically start the ssh proxy 
                echo "Autostart!"
                ssh -NfR 4389:localhost:22 -p xxxx &
        #       echo 'ssh -d running'

        sleep 5

-R means I started a reverse connection.