在自动化期间无法在 Expect Shell 脚本中建立主机的真实性时如何忽略或传递“是" [英] How to ignore or Pass 'Yes' when The authenticity of host can't be established in Expect Shell script during Automation

查看:29
本文介绍了在自动化期间无法在 Expect Shell 脚本中建立主机的真实性时如何忽略或传递“是"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 Expect Shell 脚本执行期间出现以下语句时,我想自动提供是"还是忽略它并以安全方式继续?

#!/usr/bin/expect产生 ssh $user@$host

<块引用>

无法确定主机abcdef (10.566.1.98)"的真实性.RSA 密钥指纹为 jk:94:ba:93:0b:eb:ff:df:ea:gh:hj:23:3c:hj:9c:be.您确定要继续连接吗(是/否)?

解决方案

在这个场景中使用 exp_continue.

#!/usr/bin/expect设置提示#|>|\$"生成 ssh dinesh@myhost预计 {#如果'expect'看到'(yes/no)',那么它会发送'yes'#并继续期望"循环"(yes/no)" { 发送 "yes
";exp_continue}#如果首先看到密码",则继续执行.密码"}发送root
"期望 -re $prompt

参考:预期

I want to Provide 'Yes' automatically or Ignore it and proceed in a SECURE way, when the below statement comes during execution of my Expect Shell script?.

#!/usr/bin/expect
spawn ssh $user@$host

The authenticity of host 'abcdef (10.566.1.98)' can't be established. RSA key fingerprint is jk:94:ba:93:0b:eb:ff:df:ea:gh:hj:23:3c:hj:9c:be. Are you sure you want to continue connecting (yes/no)?

解决方案

Make use of exp_continue for this scenario.

#!/usr/bin/expect 
set prompt "#|>|\$"
spawn ssh dinesh@myhost
expect {
        #If 'expect' sees '(yes/no )', then it will send 'yes'
        #and continue the 'expect' loop
        "(yes/no)" { send "yes
";exp_continue}
        #If 'password' seen first, then proceed as such.
        "password"
}
send "root
"
expect -re $prompt

Reference : Expect

这篇关于在自动化期间无法在 Expect Shell 脚本中建立主机的真实性时如何忽略或传递“是"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆