【发布时间】:2015-06-18 14:17:46
【问题描述】:
我在一个弹性 beanstalk 应用上有一个爬虫,我可以像这样通过 SSH 运行它:
source /opt/python/run/venv/bin/activatesource /opt/python/current/envcd /opt/python/current/appscrapy 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 从未启动。
想法?
【问题讨论】:
-
您确定您的代码没有错误?
-
日志中没有错误,没有部署错误,并且我可以通过 SSH 运行“scrapy crawl spidername”而不会出错。只是 cronjob 没有运行,或者它可能运行但命令没有做任何事情(?)。写 * * * * * 用户名路径命令是否正确,我这样做的方式?
标签: python amazon-web-services cron crontab amazon-elastic-beanstalk