【发布时间】:2018-07-02 13:59:28
【问题描述】:
我已经设置了一个 cron 作业来运行 Python 脚本来抓取一些网页。
/etc/crontab
GNU nano 2.3.1 File: crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=my_email_address@domain.com
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/2 * * * * root /usr/bin scrapy crawl mycrawler
但是,电子邮件告诉我...
/bin/bash: /usr/bin: Is a directory
当我手动运行脚本时,它会将数据通过管道传输到我的数据库中,但是当 cron 作业执行脚本时,什么都没有……
/bin/bash: /usr/bin: Is a directory 消息暗示了什么?!
【问题讨论】:
-
*/2 * * * * root /usr/bin scrapy crawl mycrawler应该是 ` */2 * * * * root /usr/bin/python scrapy crawl mycrawler` ...或者只是` */2 * * * * root scrapy crawl mycrawler` -
@MatthewStory 当我运行
*/2 * * * * root scrapy crawl mycrawler时,我开始收到说/bin/bash: scrapy: command not found的电子邮件 -
你的shell中
which scrapy的输出是什么? -
@MatthewStory
/usr/local/bin/scrapy。但是,python 位于/usr/bin/python,这也是脚本的依赖项 -
已发布答案...
标签: python linux cron cron-task