#!/usr/bin/expect -f   
set timeout 20
set password [lindex $argv 2]
spawn ssh -X root@[lindex $argv 0] [lindex $argv 1]
while 1 {
expect {
    "(yes/no)? $" {
        exp_send "yes\n"
    }
    "assword: $" {
        exp_send "$password\n"
        break
    }
    "Name or service not known" {
        set rc 6
        exit $rc
    }
    "Connection refused" {
        set rc 6
        exit $rc
    }
    timeout {
        set rc 6
        exit $rc
    }
}
}
expect {
    "assword: $" {
        set rc 7
        exit $rc
    }
    "Permission" {
        set rc 7
        exit $rc
    }
    "#" {
        break
    }
}

if [fork]!=0 exit
set timeout -1
expect eof

