Reputation: 1317
My local
computer is running a bash script that executes another script (locally) on a remote
like so :
#!/bin/bash
# do stuff
ssh remote@remote "/home/remote/path/to/script.sh"
echo "Done"
# do other stuff
script.sh
takes around 15 minutes to execute. Without loss of connection, script.sh
is executed completely (until the very last line). Though, Done
will never be echoed (nor will the other stuff
be executed).
Notes :
I've experimented using screen
and nohup
, but like I said, the connection is stable and script.sh
is executed thoroughly (script.sh
doesn't seem to be dropped).
I need script.sh
to be over before I can move on to doing other stuff
so I can't really run the script and detach (or I will need to know when the script is over before I can start doing other stuff
).
Everything works fine if I use a dummy script that last only 5 minutes (instead of 15).
Edit :
script.sh
used for testing :
#!/bin/bash
touch /tmp/start
echo "Start..." & sleep 900; touch /tmp/endofscript
Upvotes: 2
Views: 1698
Reputation: 1317
Adding -o ServerAliveInterval=60
fixes the issue.
The ServerAliveInterval option prevents your router from thinking the SSH connection is idle by sending packets over the network between your device and the destination server every 60 seconds. (source)
In the case of a script that takes several minutes to execute and that has no output, this will keep the connection alive and avoid it from timing out and being left hanging.
Two options :
ssh -o ServerAliveInterval=60 remote@remote "/home/remote/path/to/script.sh"
~/.ssh/config
of local
computer (replace remote
by the name of your remote or *
to enable for any remote):
Host remote
ServerAliveInterval 60
For additional information :
Upvotes: 3
Reputation: 98
Have you tried setting set -xv
in the scripts, or executing both the scripts with bash -xv script.sh
to get the details of the scripts execution?
Upvotes: 0