期望脚本不起作用

Expect script not working

下面是我尝试登录新服务器的脚本:

#!/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$

谁能告诉我哪里错了?

您缺少 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"}

}