在自动化过程中无法在Expect Shell脚本中建立主机的真实性时如何忽略或通过“是" [英] How to ignore or Pass 'Yes' when The authenticity of host can't be established in Expect Shell script during Automation
本文介绍了在自动化过程中无法在Expect Shell脚本中建立主机的真实性时如何忽略或通过“是"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当在我的Expect Shell脚本的执行过程中出现以下语句时,我想自动提供是"还是忽略它并以安全的方式继续?
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
无法确定主机"abcdef(10.566.1.98)"的真实性. RSA密钥指纹为jk:94:ba:93:0b:eb:ff:df:ea:gh:hj:23:3c:hj:9c:be. 您确定要继续连接(是/否)吗?
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)?
推荐答案
在这种情况下使用exp_continue
.
#!/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\r";exp_continue}
#If 'password' seen first, then proceed as such.
"password"
}
send "root\r"
expect -re $prompt
参考资料:期望
这篇关于在自动化过程中无法在Expect Shell脚本中建立主机的真实性时如何忽略或通过“是"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文