2016-01-27 21 views
0

下面是我的脚本,我试图登录到一个新的服务器:Expect脚本不工作

#!/usr/bin/expect 

spawn ssh [email protected]_server 

expect { 

"*(yes/no)?" {send "yes\r"} 

"*?assword:" {send "9a9c704a2fb0f9c9\r"} 

"*current*" {send "9a9c704a2fb0f9c9\r"} 

"Enter*" {send "Jan2016\r"} 

"Retype*" {send "Jan2016\r"} 

} 

但它正在退出这样的:

**[email protected]:~/scripts/new$** ./connect-to-server.sh_1 

spawn ssh [email protected]_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)? [email protected]:~/scripts/new$ 

有人可以让我知道我在哪里我错了?

回答

1

您缺少exp_continue,这将使Expect再次运行。

!/usr/bin/expect 

spawn ssh [email protected]_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"} 

} 
+0

非常感谢..它的工作! –