2016-01-27 24 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

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