内含nohup的脚本无法正确退出 [英] Scripts with nohup inside don't exit correctly

查看:87
本文介绍了内含nohup的脚本无法正确退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have script which do some processing and triggers a job in background using nohup. When we schedule this script from Oracle OEM (or it can be any scheduler job), i see the following error and show status as failed but the script actually finished without issue. How to exit the script correctly when backup ground job is started with nohup?

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

文件:test.sh

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

# end of the script

推荐答案

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

By executing start.sh in this manner you are allowing it to claim partial ownership of test.sh's output file descriptors (stdout/stderr). So whereas when most bash scripts exit, their file descriptors are closed for them (by the operating system), test.sh's file descriptors cannot be closed because start.sh still has a claim to them.

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

The solution is to not let start.sh claim the same output file descriptors as test.sh is using. If you don't care about its output, you can launch it like this:

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

告诉新进程将其stdout和stderr都发送到/dev/null .如果您确实关心它的输出,那么只需将其捕获到更有意义的位置即可:

which tells the new process to send both its stdout and stderr to /dev/null. If you do care about its output, then just capture it somewhere more meaningful:

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

这篇关于内含nohup的脚本无法正确退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆