Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I run a command like scrapy crawl empt.com in a cron job where I need to be in a specific folder to run the command for example:

/downloads/my_crawler/empt/empt/ then the command scrapy crawl empt.com

My current crontab entry looks like this: 0 */2 * * * * root /downloads/my_cralwer/empt/empt/ scrapy crawl empt.com Thanks!

share|improve this question
up vote 1 down vote accepted

Try:

0 */2 * * * * root cd /downloads/my_cralwer/empt/empt/ && scrapy crawl empt.com
share|improve this answer

Adding the following lines in crontab -e runs my scrapy crawl at 5AM everyday. 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 pwd is /home/user. Hence I skipped /home/user/ in crontab above

The cron log can be helpful while debugging

grep CRON /var/log/syslog
share|improve this answer

I know this is an old post but to get mine to work I also needed to add a path variable. Otherwise cron may not be able find scrapy. For me it was: PATH=/usr/local/bin Just locate the scrapy binary and add the path variable to a location before the cronjob in the file. I usually use crontab -e to edit the cronjob list. But utilities like webmin can also do this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.