Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何在shell脚本中打开bash/ssh会话并在远程会话中运行命令?_Linux_Bash_Shell_Ssh - Fatal编程技术网

Linux 如何在shell脚本中打开bash/ssh会话并在远程会话中运行命令?

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 .

我尝试在shell脚本中执行以下操作:

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"