set cmd [lindex $argv 0] set password [lindex $argv 1]
eval spawn $cmd
#timeout in sec, default 10
set timeout 30
expect { #first connect, no public key in ~/.ssh/known_hosts
"Are you sure you want to continue connecting (yes/no)?"{ send"yes\r" expect "password:" auth_trans $password } #already has public key in ~/.ssh/known_hosts
"password:"{ auth_trans $password }
#user equivalence already established, no password is necessary
-re "kB/s|MB/s"{ set timeout -1 expect eof } -re "Is a directory|No such file or directory"{ expect eof exit$ERR_DIR_OR_FILE_NOT_EXIST } "Connection refused"{ expect eof exit$ERR_CONNECTION_REFUSED } #connetion error