本文介绍了cron作业不会输出到nohup.out的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 start.sh bash脚本,通过 CRON JOB 在ubuntu服务器上运行



start.sh 包含 start.sh 的代码



路径 / home /ubuntu/folder1/folder2/start.sh

 #!/ bin / bash 

crawlers(){
nohup scrapy crawl first&
nohup scrapy crawl 2&
wait $!
nohup scrapy crawl 3&
nohup scrapy crawl 4&
wait
}

cd / home / ubuntu / folder1 / folder2 /
PATH = $ PATH:/ usr / local / bin
export PATH

python init.py&
wait $!
crawlers
python final.py

我的问题是如果我运行 start.sh 我自己在命令行上输出 nohup.out 文件



,但执行此通过 cronjob (虽然脚本运行正常),但不生成 nohup.out



nohup.out
中获得此cronjob的输出

解决方案

p>为什么要使用 nohup nohup 是一个命令,通知运行终端忽略挂断信号。 cron ,但没有挂机信号,因为它没有链接到终端会话。



,而不是:

  nohup scrapy第一& 

您可能想要:

  scrapy crawl first> first.txt& 

最后一个例子也适用于终端,但是当你关闭终端时, code> hup ),结束程序。


i have start.sh bash script that is running though CRON JOB on ubuntu server

start.sh contains bellow mentioned lines of code

path of start.sh is /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.sh my myself on command line it outputs in nohup.out file

but when it executes this bash file through cronjob (although scripts are running fine) its not producing nohup.out

how can i get output of this cronjob in nohup.out ?

解决方案

Why are you using nohup? nohup is 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.

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.

这篇关于cron作业不会输出到nohup.out的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 08:21