我正在本地和远程计算机(在防火墙后面)上自动执行任务。一旦我完成了远程计算机上的任务,我希望脚本返回到在本地计算机上执行命令。
#!/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/