Scrapy crawler in Cron job

后端 未结 7 1641
遥遥无期
遥遥无期 2020-12-13 15:11

I want to execute my scrapy crawler from cron job .

i create bash file getdata.sh where scrapy project is located with it\'s spiders

#!/bin/bash
cd /         


        
7条回答
  •  温柔的废话
    2020-12-13 15:28

    Adding the following lines in crontab -e runs my scrapy crawl at 5AM every day. This is a slightly modified version of crocs' answer

    PATH=/usr/bin
    * 5 * * * cd project_folder/project_name/ && scrapy crawl spider_name
    

    Without setting $PATH, cron would give me an error "command not found: scrapy". I guess this is because /usr/bin is where scripts to run programs are stored in Ubuntu.

    Note that the complete path for my scrapy project is /home/user/project_folder/project_name. I ran the env command in cron and noticed that the working directory is /home/user. Hence I skipped /home/user in my crontab above

    The cron log can be helpful while debugging

    grep CRON /var/log/syslog
    

提交回复
热议问题