使用SSH在远程服务器上启动后台进程并退出会话

编程入门 行业动态 更新时间:2024-10-24 08:32:19
本文介绍了使用SSH在远程服务器上启动后台进程并退出会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用SSH在远程服务器上启动后台进程.这是我目前的情况:

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"nohup进程&"

ssh remote_user@server "nohup process &"

这有效,因为该过程确实开始了.但是SSH会话本身直到我点击Ctr-C才结束.

This works, in that the process does start. But the SSH session itself does not end until I hit Ctr-C.

当我点击Ctr-C时,远程进程将继续在后台运行.

When I hit Ctr-C, the remote process continues to run in the background.

我想将ssh命令放在可以在本地运行的脚本中,所以我希望一旦远程进程启动,ssh会话就会自动退出.

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的"-f"选项告诉ssh在后台运行远程命令并立即返回.例如,

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"

如果键入上面的内容,则将立即返回shell提示,然后您将看到"foo"输出.五秒钟后,您将看到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.

更多推荐

使用SSH在远程服务器上启动后台进程并退出会话

本文发布于:2023-06-10 22:52:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   进程   器上   SSH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!