I am using SSH to start a background process on a remote server. This is what I have at the moment:
ssh [email protected] "nohup process &"
This works, in that the process does start. But the SSH session itself does not end until I hit Ctr-C.
When I hit Ctr-C, the remote process continues to run in the background.
I would like to place the ssh command in a script that I can run locally, so I would like the ssh session to exit automatically once the remote process has started.
Is there a way to make this happen?
ssh into your remote box. type screen Then start the process you want. Press Ctrl-A then Ctrl-D. This will detach your screen session but leave your processes running.
To execute SSH command remotely in the background without this issue, you need to prevent SSH from blocking for input by redirecting the output to /dev/null. You will then also need to send your SSH client session to the background. You can achieve both effects by using the -n and -f options for the SSH client.
ssh into your remote box. Type screen Then start the process you want. Press Ctrl-A then Ctrl-D . This will "detach" your screen session but leave your processes running.
The "-f" option to ssh tells ssh to run the remote command in the background and to return immediately. E.g.,
ssh -f user@host "echo foo; sleep 5; echo bar"
If you type the above, you will get your shell prompt back immediately, you will then see "foo" output. Five seconds later you will then see "bar" output. In the meantime, you could have been using the shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With