11

I am trying to do

[me@myPc]$ ssh me@server "nohup myBashScript.sh &"

My goal is to launch the process on the server, and then immediately return.

It is not working: The job is started on server, but I still get the output on myPc and bash wait for completion prior to asking me for another command.

Why ? It's not supposed to ! Any way to avoid that ?

  • myPc is RHEL6.2
  • server is ubuntu 10.04 and
  • both runs openssh

2 Answers2

13

As long as input or output are still open, ssh will keep the connection open. To solve this, make sure the input and output are not open.

For instance, use ssh -n and redirect your output:

ssh -n me@example.com "nohup myscript.sh >/dev/null 2>&1 &"
0

Is it really necessary to run nohup via ssh? In my tests I did not find ANY difference running command with and without nohup. It seems that ssh does not send HUP anyway. This works equally as with nohup:

ssh me@server "myBashScript.sh >/dev/null 2>&1 &"

The key to solution here is redirecting stdout and stderr as already mentioned in the accepted answer. Without it SSH reads from those descriptors, and returns only after they are closed.

Alek
  • 125