Linux 如何在shell脚本中打开bash/ssh会话并在远程会话中运行命令?
我尝试在shell脚本中执行以下操作:Linux 如何在shell脚本中打开bash/ssh会话并在远程会话中运行命令?,linux,bash,shell,ssh,Linux,Bash,Shell,Ssh,我尝试在shell脚本中执行以下操作: bash; 在bash上下文中: 运行/a.out 在/a.out上下文中,我需要模拟密钥点: yes 3292 no 我怎么做?自从&、&和以来,我的所有尝试都失败了在主shell上下文而不是bash中执行后续命令 bash && echo "yes" > /dev/console 我已经看到了使用本机shell命令没有其他选择吗?我不想依赖其他工具。看看它,它通过用户提供的脚本与交互式程序“对话” 用法 expect .
bash;
在bash上下文中:
- 运行
/a.out
/a.out
上下文中,我需要模拟密钥点:
yes
3292
no
我怎么做?自从&
、&
和以来,我的所有尝试都失败了代码>在主shell上下文而不是bash中执行后续命令
bash && echo "yes" > /dev/console
我已经看到了使用本机shell命令没有其他选择吗?我不想依赖其他工具。看看它,它通过用户提供的脚本与交互式程序“对话”
用法
expect ./interact
或使交互
可执行(chmod a+x交互
):
其中交互
是以下脚本:
#!/usr/bin/expect
spawn ./a.out
send -- "yes\r"
expect "3292\r"
send -- "no\r"
这只是一个简单的示例,手册页中有很多深入的解释,还有安装附带的示例脚本
参考资料
#!/usr/bin/expect
spawn ./a.out
send -- "yes\r"
expect "3292\r"
send -- "no\r"