我的 local
计算机正在运行一个 bash 脚本,该脚本在 remote
上执行另一个脚本(本地),如下所示:
#!/bin/bash
# do stuff
ssh remote@remote "/home/remote/path/to/script.sh"
echo "Done"
# do other stuff
script.sh
执行大约需要 15 分钟。 没有丢失连接,script.sh
被完全执行(直到最后一行)。但是,Done
永远不会被回显(也不会执行 other stuff
)。
注意事项:
我已经尝试过使用 screen
和 nohup
,但就像我说的,连接是稳定的,并且 script.sh
被彻底执行(script.sh
没有好像掉线了)。
我需要 script.sh
结束才能继续执行 other stuff
所以我无法真正运行脚本并分离(或者我需要知道脚本何时在我开始做other stuff
之前结束。
如果我使用仅持续 5 分钟(而不是 15 分钟)的虚拟脚本,一切都会正常。
编辑:
script.sh
用于测试:
#!/bin/bash
touch /tmp/start
echo "Start..." & sleep 900; touch /tmp/endofscript
答案 0 :(得分:2)
添加 xxxxxx 1 of 100000
...
xxxxxx 99999 of 100000
xxxxxx 100000 of 100000
解决了该问题。
ServerAliveInterval 选项每 60 秒通过网络在您的设备和目标服务器之间发送数据包,从而防止您的路由器认为 SSH 连接处于空闲状态。 (source)
如果脚本需要几分钟才能执行并且没有输出,这将使连接保持活动状态并避免它超时和挂起。
两个选项:
-o ServerAliveInterval=60
ssh -o ServerAliveInterval=60 remote@remote "/home/remote/path/to/script.sh"
计算机的 ~/.ssh/config
(将 local
替换为您的遥控器名称或 remote
以启用任何遥控器):
*
更多信息:
答案 1 :(得分:0)
您是否尝试在脚本中设置 set -xv
,或者使用 bash -xv script.sh
执行两个脚本以获取脚本执行的详细信息?