Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/19996089/use-ssh-to-start-a-background-process-on-a-remote-server-and-exit-session

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...