Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Elastic Beanstalk上的Cronjob未运行_Python_Amazon Web Services_Cron_Crontab_Amazon Elastic Beanstalk - Fatal编程技术网

Python Elastic Beanstalk上的Cronjob未运行

Python Elastic Beanstalk上的Cronjob未运行,python,amazon-web-services,cron,crontab,amazon-elastic-beanstalk,Python,Amazon Web Services,Cron,Crontab,Amazon Elastic Beanstalk,我在elastic beanstalk应用程序上有一个scrapy crawler,我可以通过SSH运行它,如下所示: 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

我在elastic beanstalk应用程序上有一个scrapy crawler,我可以通过SSH运行它,如下所示:

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
# 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.
  • source/opt/python/run/venv/bin/activate
  • source/opt/python/current/env
  • cd/opt/python/current/app
  • scrapy crawl spidername
我想设置一个cronjob来为我运行这个。所以我听从了建议

我的
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
# 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.
我的
spider\u cron.txt
文件如下所示:

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
# 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\u spidername
。但是当我运行
crontab-l
crontab-uroot-l
时,它会说不存在crontab

我没有收到任何日志错误、部署错误,并且从未创建我尝试将cron输出到的
/tmp/mycommand.log
文件。好像工作还没开始


想法?

您的spider_cron.txt在/opt/python/current/app/之后但在scrapy之前有一个额外的空间。因此,正在运行的命令只是一个文件夹“/opt/python/current/app/”

你的

应该是

40 9 * * * root /opt/python/current/app/scrapy crawl spidername > /dev/null

键入“/opt/python/current/app/scrapy crawl spidername”是否启动爬虫程序?

您确定您的代码没有错误吗?日志中没有错误,没有部署错误,并且我可以通过SSH无错误地运行“scrapy crawl spidername”。只是cronjob没有运行,或者它确实运行了,但是命令没有做任何事情(?)。按照我的方式编写*****用户名路径命令是否正确?不,Scrapy不是/app/中的文件。这是一个已安装的命令。您的解决方案无效,而且不正确。我刚刚用我所做的一些更改更新了我的问题,但仍然不起作用。现在,您已经编辑了看起来很有效的问题。如果您登录并且不更改目录。您可以通过键入“/opt/python/current/app/runcrawler.sh”来运行脚本吗?如果我执行
sudo crontab crawl\u spidername
并将其添加到根crontab,它就会工作。如果我这么做,一切都会好起来的。但是,当我将文件放入
/etc/cron.d/
中时,似乎还不足以让cron实际加载并运行。这意味着每次重新启动服务器或类似的东西时,我必须进入实例并添加cronjob。我特别想看看乔·卡萨东特的帖子