【问题标题】:cant get a cron job running on debian无法在 debian 上运行 cron 作业
【发布时间】:2011-11-17 16:49:09
【问题描述】:

我有一个 Debian VPS,上面有几个网站。我目前正在大量使用 django。

我想要一个 cron 作业在我的一个 django 站点中运行和安排一个脚本。结果是我无法让 Cron 作业运行,而且我不确定如何对其进行排序,因为我没有很多 Linux 经验。

我的 /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
HOME=/home/shofty
LOGNAME=shofty
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO="info@webbricks.co.uk"

# 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 )
#

所以我已经在“crontab -e”中设置了工作

50 10 * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virrtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks

但它似乎在我尝试的时间没有运行(10:50 是任意的,我每隔几分钟调整一次以使其在更改设置或其他设置后运行)。

我认为 cron 正在运行,因为我可以做到

/etc/init.d/cron stop

但是带有 start 的相同命令失败。显然在让它再次运行之后开始。 从我读过的所有内容来看,ps aux 的输出暗示它正在运行。

root@shoftys - server>_ /home/shofty# ps aux | grep cron 
root     19106  0.0  0.0  18548   948 ?        Ss   10:42   0:00 /usr/sbin/cron
root     27130  0.0  0.0   3876   600 pts/0    S+   15:52   0:00 grep cron

我在 crontab 的命令中添加了 > /home/shofty/virtualenvs/webbricks/cron.log,但它似乎不想输出日志文件。 我在 /var/log/cron 中什么也没有得到,它只是说它是一个新文件。

作为一个菜鸟,我有点不确定下一步该去哪里,请对 linux、debian 和 cron 有更多了解的人建议下一步该去哪里?

【问题讨论】:

  • 在用 sillyMunky 进行了相当多的检查之后,这归结为没有运行该作业的权限。通过尝试手动运行作业发现了它。不知道为什么我没有权限,但认为这值得一个新问题。

标签: linux cron debian crontab


【解决方案1】:

一切都比这简单多了!

恢复对 crontab 的所有更改,而是根据需要在 /etc/cron.daily 或 /etc/cron.hourly 中添加指向脚本的链接。您希望它多久运行一次?如果更频繁或更精确的时间,我也可以帮助你。但是,如果您只想运行每日/每小时脚本,请将其(或指向它的链接)放在其中一个目录中。

如果你想控制你的脚本运行的具体时间,最好把它放在 crontab 中: 0 1 * * * 用户名 /path/to/my/script

您只是缺少用户名!发生这种情况时,您的 cron-tab 看起来会出错,这就是您无法重新启动 /etc/init.d/cron 的原因;)

p.s 添加到 cron.daily 目录的链接:

ln -s /path/to/my/script /etc/cron.daily/scriptname

【讨论】:

  • 更清楚了,谢谢,我不介意把它绑定到凌晨 1 点,我该怎么做?
  • 我已经编辑了答案,包括如何修复您使用的方法(在用户名字段中添加)
  • 抱歉,误读了有关启动和停止它的内容。顺便说一句,/etc/init.d/cron 状态会告诉您它是否正在运行;)您在发布的行中缺少用户名(介于时间和命令之间),这可能会阻止 cron 正常运行。
  • 安全地假设我已经完成了一个 SU 以便能够编辑我需要在该文件中使用 root 的 crontab? ---- 我仍然不确定为什么我没有在 /var/log/cron 处创建日志文件
  • /etc/init.d/cron status 不起作用,这可能与它有关吗?告诉我用法:/etc/init.d/cron {start|stop|restart|reload|force-reload}。
猜你喜欢
  • 2016-08-21
  • 2014-12-17
  • 2015-09-20
  • 1970-01-01
  • 2014-02-02
  • 2012-10-17
  • 2023-04-02
  • 2017-12-17
  • 1970-01-01
相关资源
最近更新 更多