以下是我尝试登录新服务器的脚本:
#!/usr/bin/expect
spawn ssh root@new_server
expect {
"*(yes/no)?" {send "yes\r"}
"*?assword:" {send "9a9c704a2fb0f9c9\r"}
"*current*" {send "9a9c704a2fb0f9c9\r"}
"Enter*" {send "Jan2016\r"}
"Retype*" {send "Jan2016\r"}
}
但它正在退出:
**mayankp@mayankp:~/scripts/new$** ./connect-to-server.sh_1
spawn ssh root@new_server
The authenticity of host 'new_server (new_server)' can't be established.
ECDSA key fingerprint is f4:5d:54:14:6c:e3:88:b5:eb:1f:39:bd:34:f6:64:9d.
Are you sure you want to continue connecting (yes/no)? mayankp@mayankp:~/scripts/new$
有人能让我知道我哪里错了吗?
答案 0 :(得分:1)
您遗失了exp_continue
,这将使Expect
再次投放。
!/usr/bin/expect
spawn ssh root@new_server
expect {
"*(yes/no)?" {send "yes\r";exp_continue}
"*?assword:" {send "9a9c704a2fb0f9c9\r";exp_continue}
"current" {send "9a9c704a2fb0f9c9\r";exp_continue}
"Enter*" {send "Jan2016\r";exp_continue}
"Retype*" {send "Jan2016\r";exp_continue}
"\\\$" { puts "matched prompt"}
}