我通过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文件中?
发布于 2020-08-30 03:51:41
来自info nohup
23.4‘nohup’:运行对hangups =============================================免疫的命令
‘’nohup‘在忽略挂起信号的情况下运行给定的命令,以便在您注销后该命令可以在后台继续运行。
..。
如果标准输出是终端,则将命令的标准输出附加到‘nohup.out’文件中;
如果无法写入,则执行waltera:将当前目录中的写入权限/空间附加到文件‘$HOME/nohup.out’中;如果无法写入,则不运行命令。
..。
但是,如果关闭了标准输出,则会将标准错误终端输出附加到文件‘nohup.out’或‘$HOME/nohup.out’中,如上所述。
当cron
执行脚本时,标准输出既不是终端,也不是封闭的,因此nohup
没有理由重定向任何输出。
没有终端的nohup
的另一个demo
是当您使用另一个nohup
启动您的script2.sh时,它有一个nohup
命令
nohup ./script2.sh > masternohup.out
script3.sh
的输出将写入masternohup.out
。
发布于 2020-08-26 14:11:46
来自man nohup
...
If standard input is a terminal, redirect it from an unreadable file.
If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise.
If standard error is a terminal, redirect it to standard output.
To save output to FILE, use 'nohup COMMAND > FILE'.
...
所以它可以是$HOME/nohup.out
中的任何一种,最好使用它来控制输出:
nohup COMMAND &> FILE
发布于 2020-08-30 03:59:35
在现代,你不需要nohup
。
Shell转义方法允许进程离开其进程组,并且永远不会收到SIGHUP
或任何其他指向进程组的信号。
在bash shell中:
(command &>log.txt &)
https://stackoverflow.com/questions/63590342
复制相似问题