方案一
#! /usr/bin/expect
set host www.baidu.com
set passwd abcd1345
spawn ssh -p 2222 hanzl111@$host
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
interact
方案二
#!/usr/bin/expect
set ip 192.168.11.1
set password abcd1345
set timeout 10
spawn ssh -p 22 hanzl@$ip
expect {
"*yes/no" { send "yes^M"; exp_continue}
"*password:" { send "$password\n" }
}
interact