cron job doesn't output to nohup.out

僤鯓⒐⒋嵵緔 提交于 2021-02-07 05:06:01

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/14145250/cron-job-doesnt-output-to-nohup-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!