ssh remote command does not return

2019-02-14 08:46发布

问题:

I am running ssh somehost "service XXX restart" and the shell hangs.

The service is nodeJS and I see express is listening on port ... print I made in server.js and that's it, it does not return to prompt, it simply hangs.

I tried nohup and & but it does not help. What else can I try?

回答1:

turns out that using -t resolves the issue.

ssh -t root@somehost "service XXX restart" does not hang.

other suggestions from the comments that might resolve this:

  • node myScript.js & disown
  • exec node myScript.js &


回答2:

Using ssh -t does not hang, but it terminates the remote process too.

What works for me is just to run the remote process in background as shown below:

ssh somehost /path/to/some/script augment1 augment2 &


标签: ssh