我在弹性beanstalk应用程序上有一个scrapy爬虫,我可以通过SSH运行,如下所示:
-
source /opt/python/run/venv/bin/activate
-
source /opt/python/current/env
-
cd /opt/python/current/app
-
scrapy crawl spidername
我想设置一个cronjob来为我运行这个 . 所以我按照建议here .
我的 setup.config
文件如下所示:
container_commands:
01_cron_hemnet:
command: "cat .ebextensions/spider_cron.txt > /etc/cron.d/crawl_spidername && chmod 644 /etc/cron.d/crawl_spidername"
leader_only: true
我的 spider_cron.txt
文件如下所示:
# The newline at the end of this file is extremely important. Cron won't run without it.
* * * * * root sh /opt/python/current/app/runcrawler.sh &>/tmp/mycommand.log
# There is a newline here.
我的 runcrawler.sh
文件位于 /opt/python/current/app/runcrawler.sh
,看起来像这样
#!/bin/bash
cd /opt/python/current/app/
PATH=$PATH:/usr/local/bin
export PATH
scrapy crawl spidername
我可以导航到 /etc/cron.d/
并看到那里存在 crawl_spidername
. 但是,当我运行 crontab -l
或 crontab -u root -l
时,它表示没有crontab存在 .
我没有得到日志错误,没有部署错误,我尝试输出cron的 /tmp/mycommand.log
文件永远不会被创建 . 似乎cronjob从未开始 .
想法?
1 回答
你的spider_cron.txt在 /opt/python/current/app/ 之后但在 scrapy 之前有一个额外的空格 . 所以正在运行的命令只是一个文件夹"/opt/python/current/app/"
你的
应该
输入“ /opt/python/current/app/scrapy crawl spidername ”是否会启动您的抓取工具?