linux – 如何使用expect命令创建else语句?
发布时间:2021-03-15 15:46:37 所属栏目:Linux 来源:网络整理
导读:如果已知主机不存在,我有跟随expect脚本添加已知主机. #!/usr/bin/expectspawn ssh user@domain "cd /home/user"expect "Are you sure you want to continue connecting (yes/no)?"send "yesr"interact ssh第一次进入设备时脚本工作正常但是如果我第一次ssh
如果已知主机不存在,我有跟随expect脚本添加已知主机. #!/usr/bin/expect spawn ssh user@domain "cd /home/user" expect "Are you sure you want to continue connecting (yes/no)?" send "yesr" interact ssh第一次进入设备时脚本工作正常但是如果我第一次ssh到设备中,它会抛出一个错误 send: spawn id exp6 not open while executing "send "yesr"" (file "./testing_spawn.sh" line 4) 大概是因为它继续期待字符串您确定要继续连接(是/否)? 如果该消息没有出现,我如何告诉脚本只是进行交互? 解决方法只有在命令提示符出现之前,才使用expect_before匹配“未知主机”问题:#!/usr/bin/expect spawn ssh user@domain expect_before "*(yes/no)?" { send "yesr" } expect "*# " interact (编辑:武汉站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |