【发布时间】:2012-01-11 11:22:15
【问题描述】:
我编写了以下期望脚本以自动 ssh 登录到远程 Linux 机器 并运行命令“cat /etc/APP_VERSION.txt 文件”
有时我没有从 ssh 命令询问-
"Are you sure you want to continue connecting (yes/no)?"
所以在这种情况下,第一个期望仍然等待字符串“(是/否)?” -:(
而不是继续第二个期望 - “密码:”?
如何解决这个问题? ,
我的意思是如果“您确定要继续连接(是/否)吗?”行 不是从 ssh 中出现的
那么我们必须到下一个expect "password:",但是怎么做呢?
remark1 - 如果问题“您确定要继续连接(是/否)?” , 出现然后期望脚本工作正常没有任何问题 .
remark2 - 我不能使用超时正值(如超时 10),因为 ssh 本身有延迟
。 . . .
我的期望脚本:(这个期望是我的 ksh 脚本的一部分)
.
.
.
APP_MACHINE=172.12.6.190
set timeout -1
spawn ssh $APP_MACHINE
expect {
"(Are you sure you want to continue connecting yes/no)?"
{ send "yes\r" }
}
expect password: {send PASS123\r}
expect > {send "cat /etc/APP_VERSION.txt\r"}
expect > {send exit\r}
expect eof
.
.
.
。 . . . .
我的 linux 机器上的 ssh 示例
ssh APP_MACHINE
The authenticity of host 'APP_MACHINE (172.12.6.190 )' can't be established.
RSA key fingerprint is 1e:8a:3d:b3:e2:8c:f6:d6:1b:16:65:64:23:95:19:7b.
Are you sure you want to continue connecting (yes/no)?
【问题讨论】:
标签: linux bash shell expect tk