cron没有定期开火

时间:2014-08-17 15:06:08

标签: django cron crontab

我想设置一个每5分钟从api中获取一些故事的cron,如果出现任何新故事,就会发邮件。这是我的crontab文件。 (使用django管理命令执行此操作)。我解雇了管理命令并向我发送了正确的信息,但是当我试图设置相同的cronjob时,它没有触发。这是我的crontab文件

vi /etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

5 * * * * root /home/anurag/projects/virtualenvs/django6/bin/python /home/anurag/Documents/HNStories/hnstories/manage.py get_stories >> /home/anurag/cron_log.txt

以下是其许可

ls -l /etc/crontab 
-rw-r--r-- 1 root root 884 Aug 17 20:20 /etc/crontab

此外,我无法在syslog文件中看到任何警告和错误

cat /var/log/syslog | grep crontab
Aug 17 12:58:01 anurag cron[1257]: (*system*) RELOAD (/etc/crontab)
Aug 17 17:24:01 anurag cron[8534]: (*system*) RELOAD (/etc/crontab)
Aug 17 20:21:01 anurag cron[1139]: (*system*) RELOAD (/etc/crontab)

我还尝试重新启动crontab并重新启动计算机。但我无法解决这个问题。

1 个答案:

答案 0 :(得分:1)

每5分钟执行一次的正确语法是

*/5 * * * * root /home/anurag/projects/virtualenvs/django6/bin/python /home/anurag/Documents/HNStories/hnstories/manage.py get_stories >> /home/anurag/cron_log.txt 

命令未执行的另一个原因可能是/etc/crontab

末尾缺少换行符

编辑: 您可能还希望查看django-extensions,它提供了一个命令扩展(runjobs)来运行预定作业。