【发布时间】:2020-08-30 06:32:14
【问题描述】:
我正在通过 crontab 执行 script1.sh。
script1.sh
echo "Crontab is executing this script."
echo "Some code is running here."
cd cron
./script2.sh
“script1.sh”正在调用“script2.sh”。
'script2.sh'
echo "Exceuting script2."
echo "log of script3.sh is inserting in nohup.out file."
nohup sh script3.sh &
echo "Above syntax is not logging in nohup.out file. but this syntax is 'sh script3.sh > nohup.out &' is logging in nohup.out file. Why is it so?"
'script2.sh' 正在调用'script3.sh',但无法登录 nohup.out 文件。对于日志记录,使用以下语法。
nohup sh script3.sh &
'script3.sh' 包含下面提到的代码行。
echo "Executing script3. This is just test example to simulate the things."
为什么日志没有插入到 nohup.out 文件中?
【问题讨论】:
-
您的问题不清楚。 “为什么日志没有插入 nohup.out 文件?” - 什么日志? “script3.sh”有什么作用?我们能看到吗?请提供一个可重现的最小示例。
-
@StephenC ...在实际场景中'script3.sh'将是应用服务器日志。
-
@user752590 :文本 Executing script3. ..... 应该在
nohup.out. If it isn't, what else do you see in this file? Is ``nohup.out中为空?您是否查看了正确 nohup.out,而不是之前运行的剩余文件(检查时间戳)? -
@user1934428 ... "nohup.out 是空的吗?"... nohup.out 不存在。
-
crontab 不在交互式 shell 中运行,因此 crontab 没有标准输出或标准输入。这就是 crontab 中的 nohup 不生成 nohup.out 的原因。请使用重定向 &>1 来存储您的日志。阅读此stackoverflow.com/questions/14145250/…