VNC Tunnel using ssh Expect script

Just a Little script i wrote to log on to a server and set up a ssh tunnel mapping a remote VNC port to your local machine. If the connection is refused the script will keep trying at increased intervals. To make the script work you need to create a credentials file and put the following in it: set username "yoursshusername" set passwd "yoursshpassword" Remember to chmod the credentials file, just in case, because the details are stored in plain text. You will need to edit the script to point at your credentials file and server name. #! /usr/bin/expect # Set this to the location of your credentials file set cred "~/scripts/credentials" # Set This to the server name set server "" #read in credentials file source $cred set responseok "false" set passwdok "false" set sleeptime 2 while {$responseok == "false"} { send "Logging on to $server \n" sleep 1 eval spawn ssh -L 5902:localhost:5902 [email protected]$server match_max 100000 expect { "Connection refused" { send_user "\n Connection refused... Trying again in $sleeptime Seconds\n\n" set responseok false sleep $sleeptime incr sleeptime } "unknown host" { send_user "\n Unknown Host... \n\n" set responseok false sleep 10 abort } "assword: " { set responseok true } } } send "$passwd\r" expect "$ " interact