linux - 混合远程期望脚本和本地 bash 命令的最佳方法是什么?

标签 linux bash expect

我正在本地和远程计算机(在防火墙后面)上自动执行任务。一旦我完成了远程计算机上的任务,我希望脚本返回到在本地计算机上执行命令。

#!/usr/bin/expect -f
set timeout -1
spawn ssh username@host
expect "Password: "
send "mypassword\r"
expect "username@host:~$"
...do some stuff...
send "exit\r"
expect eof

[then, once on the local machine, change directories and do other things]

附加 bash 命令的最佳方法是什么?我想我可以从bash开始,在其中调用expect,然后在expect完成后简单地返回到bash。

最佳答案

预期基于 Tcl ,因此它可以运行相同的命令。但是,如果您的目标是运行 bash 命令,那么最好的选择是从 bash 作为单独的脚本运行它们,就像您在上一句中建议的那样。

关于linux - 混合远程期望脚本和本地 bash 命令的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30361078/

相关文章:

linux - aws ec2 ubuntu 需要我的密码

linux - 在 sh 中对字符串使用运算符

environment-variables - 如何在 Expect 脚本中访问环境变量?

php 在前台运行另一个脚本

linux - Bash Printf 格式不正确

linux - 用于查找、处理和重命名文件的 Bash 脚本?

狂欢文件 : run process in parallel and stop when one is over

python - 无法将变量传递给 python 中的 bash 命令

installation - 安装bash的expect

python 子进程输出被截断