繁体   English   中英

Shell脚本在后台使用ssh远程运行命令whit nohup,但是无法关闭此ssh进程。 但是我用的屏幕都完美

[英]shell script use ssh remote run command whit nohup in the background,but this ssh process can not be close. but I use the screen is all perfect

我使用shell脚本运行ssh命令在后台远程执行cammand whit nohup,但是ssh connect无法退出,shell脚本也无法退出。 这是为什么,这是我想知道的。

当我使用屏幕命令是完美的。

我发现用nohup执行命令时,命令父进程ID是bash进程ID的ssh连接符。当我杀死ssh连接时,常用父进程ID是1(init)。

当我使用screen时,命令父进程ID是bash进程ID的screen carete.screen父进程ID为1。

对不起,我英语不好

如果您的应用程序之一仍连接到ssh以进行终端输入/输出,则可能不允许ssh退出。

您可以尝试重定向后台进程的输入:

nohup sh /tmp/cmd.sh </dev/null &

也许输出:

nohup sh /tmp/cmd.sh </dev/null >/dev/null 2>&1 &

&>/dev/null可以是一个快捷方式,但根据shell可能并不总是有效。

警告:让进程在无限循环上运行是一件非常糟糕的事情,并且可能很危险,即可能烧毁系统。

至少您应该使用sleep修改循环,这样可以减轻循环的负担,因此以后也可以轻松跟踪它:

while true; do sleep 10; done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM