如果已知主机不存在,我有跟随expect脚本添加已知主机.
#!/usr/bin/expect spawn ssh user@domain "cd /home/user" expect "Are you sure you want to continue connecting (yes/no)?" send "yes\r" interact
ssh第一次进入设备时脚本工作正常但是如果我第一次ssh到设备中,它会抛出一个错误
send: spawn id exp6 not open while executing "send "yes\r"" (file "./testing_spawn.sh" line 4)
大概是因为它继续期待字符串您确定要继续连接(是/否)?
如果该消息没有出现,我如何告诉脚本只是进行交互?
解决方法
只有在命令提示符出现之前,才使用expect_before匹配“未知主机”问题:
#!/usr/bin/expect spawn ssh user@domain expect_before "*(yes/no)?" { send "yes\r" } expect "*# " interact