Use SSH to start a background process on a remote server, and exit session

后端 未结 4 1339
南方客
南方客 2021-02-02 07:22

I am using SSH to start a background process on a remote server. This is what I have at the moment:

ssh remote_user@server.com \"nohup process &\"

4条回答
  •  遇见更好的自我
    2021-02-02 08:02

    When using nohup, make sure you also redirect stdin, stdout and stderr:

    ssh user@server 'DISPLAY=:0 nohup xeyes < /dev/null > std.out 2> std.err &'
    

    In this way you will be completely detached from the remote process. Be carefull with using ssh -f user@host... since that will only put the ssh process in the background on the calling side. You can verify this by running a ps -aux | grep ssh on the calling machine and this will show you that the ssh call is still active, but just put in the background.

    In my example above I use DISPLAY=:0 since xeyes is an X11 program and I want it started on the remote machine.

提交回复
热议问题