内置nohup的脚本无法正确退出

时间:2015-04-17 21:36:47

标签: bash shell nohup

我们有脚本进行一些处理并使用nohup在后台触发作业。当我们从Oracle OEM安排此脚本(或者它可以是任何调度程序作业)时,我看到以下错误并显示状态为失败,但脚本实际上没有问题。如何在使用nohup启动备份地面作业时正确退出脚本?

Remote operation finished but process did not close its stdout/stderr

file:test.sh

#!/bin/bash
# do some processing
...
nohup ./start.sh 2000 &

# end of the script

1 个答案:

答案 0 :(得分:11)

通过以这种方式执行start.sh,您允许它声明test.sh的输出文件描述符(stdout / stderr)的部分所有权。因此,当大多数 bash脚本退出时,它们的文件描述符将被关闭(由操作系统),test.sh的文件描述符无法关闭,因为start.sh仍然有声称他们。

解决方案是不让start.sh声明与test.sh使用相同的输出文件描述符。如果您不关心它的输出,可以像这样启动它:

nohup ./start.sh 2000 1>/dev/null 2>/dev/null &

告诉新进程将其stdout和stderr发送到/dev/null。如果你关心它的输出,那么只需将它捕获到更有意义的地方:

nohup ./start.sh 2000 1>/path/to/stdout.txt 2>/path/to/stderr.txt &