![](/img/trans.png)
[英]Background shell script can't reach directories after ssh logout, even with nohup
[英]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.