cron job doesn't output to nohup.out

11,003

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.

Share:
11,003
akhter wahab
Author by

akhter wahab

Python developer having expertise in data scraping. working on this domain from past One decade.

Updated on August 14, 2022

Comments

  • akhter wahab
    akhter wahab over 1 year

    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 ?