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

后端 未结 4 1331
南方客
南方客 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 07:44

    Well this question is almost 10 years old, but I recently had to launch a very long script (taking several hours to complete) on a remote server and I found a way using the crontab.

    If can edit your user's crontab on the remote server, connect with ssh to the server, edit the crontab and add an entry that will start your script the next minute. Let's say it's 15h03. Add this line :

    4 15 * * * /path/to/your/script.sh
    

    save your crontab, wait a minute for the script to be launched. Then edit again your crontab to remove this entry.

    You can then safely exit ssh, even shut down your computer while the script is running.

提交回复
热议问题