bash cron 作业不会输出到 nohup.out
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14145250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cron job doesn't output to nohup.out
提问by akhter wahab
i have start.shbash script that is running though CRON JOBon ubuntu server
我有start.shbash 脚本,它 通过 ubuntu 服务器上的CRON JOB运行
start.shcontains bellow mentioned lines of code
start.sh包含下面提到的代码行
path of start.shis /home/ubuntu/folder1/folder2/start.sh
start.sh 的路径是/home/ubuntu/folder1/folder2/start.sh
#!/bin/bash
crawlers(){
nohup scrapy crawl first &
nohup scrapy crawl 2nd &
wait $!
nohup scrapy crawl 3rd &
nohup scrapy crawl 4th &
wait
}
cd /home/ubuntu/folder1/folder2/
PATH=$PATH:/usr/local/bin
export PATH
python init.py &
wait $!
crawlers
python final.py
my issue is if i run start.shmy myself on command line it outputs in nohup.outfile
我的问题是,如果我自己在命令行上运行start.sh,它会在nohup.out文件中输出
but when it executes this bash filethrough cronjob(although scripts are running fine) its not producing nohup.out
但是当它通过cronjob执行这个bash 文件时(虽然脚本运行良好)它不会产生nohup.out
how can i get outputof this cronjob in nohup.out?
我怎样才能得到输出这个的cronjob中的nohup.out?
回答by Fredrick Brennan
Why are you using nohup? nohupis a command that tells the running terminal to ignore the hangup signal. cron, however, has no hangup signal, because it is not linked to a terminal session.
你为什么使用nohup?nohup是一个命令,告诉正在运行的终端忽略挂断信号。cron但是,没有挂断信号,因为它没有链接到终端会话。
In this case, instead of:
在这种情况下,而不是:
nohup scrapy crawl first &
You probably want:
你可能想要:
scrapy crawl first > first.txt &
The last example also works in a terminal, but when you close the terminal, the hangup signal (hup) is sent, which ends the program.
最后一个示例也适用于终端,但是当您关闭终端时,hup会发送挂断信号 ( ),从而结束程序。

