cron作业不输出到nohup.out

akh*_*hab 12 python bash ubuntu cron crontab

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

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
Run Code Online (Sandbox Code Playgroud)

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

但是当它通过cronjob执行这个bash文件时(尽管脚本运行正常)它不会产生nohup.out

我怎样才能得到输出这个的cronjob中的nohup.out

Fre*_*nan 22

你为什么用nohupnohup是一个命令,告诉运行终端忽略挂起信号.cron但是,没有挂断信号,因为它没有链接到终端会话.

在这种情况下,而不是:

nohup scrapy crawl first &
Run Code Online (Sandbox Code Playgroud)

你可能想要:

scrapy crawl first > first.txt &
Run Code Online (Sandbox Code Playgroud)

最后一个示例也适用于终端,但是当您关闭终端时,hup会发送挂起信号(),从而结束程序.