Debian 上的 Cron 作业-不起作用

Debian 上的 Cron 作业-不起作用

这可能是一个有点无聊的话题,但我昨晚整晚都在讨论它,似乎无法让它启动并运行。

root@host:~# /etc/init.d/cron status
Checking periodic command scheduler...done (running).

因此该服务似乎运行良好。

我尝试过许多简单的测试 cron 作业,但是都没有起作用:

* * * * * echo "Hello world !!!" 2&>1 >> /tmp/lol.log
05 06 * * mon-fri echo "Nightly Backup Successful: $(date)" >> /tmp/test.log

除此之外,其中一位程序员给了我这份工作,我知道这份工作在我们当前的生产服务器上完美运行:

* * * * * wget -q -O /dev/null http://www.hostname.com/test/email_au

所以最后,这些方法似乎都不起作用,我在网上浏览了很多指南,但似乎都不起作用。可能缺少了什么?

编辑:etc 中唯一与 cron 相关的文件是:cron.d、cron.daily、cron.hourly、cron.monthly、cron.weekly、crontab。那里没有 cron.deny 或 cron.allow 文件。我还尝试以 root 身份运行这些 cron 作业。

答案1

您是否检查过 cron 日志以了解实际发生了什么?

通常在 debian 系统中 cron 日志是被禁用的,请在 rsyslogd 或 syslogd 中通过取消注释相应配置文件中的 cron 日志行来启用此功能。

cron.*              /var/log/cron.log

答案2

检查是否有文件 /etc/cron.allow 或 /etc/cron.deny。可以限制用户(但不是 root)运行 cron 作业。

来自 man 1 crontab:

If  the  /etc/cron.allow  file exists, then you must be listed
(one user per line) therein in order to be allowed to use this
command. If the /etc/cron.allow file does not exist but the
/etc/cron.deny file does exist, then you must not be listed in
the /etc/cron.deny file in order to use this command.

答案3

您的 cron 文件是什么样的?我从一些经验中知道,某些版本的 Cron 存在错误,即 cron 会忽略 cron 文件的最后一行(这意味着您的命令可能会被忽略,因为它可能位于文件的最后一行)。也许这可能是问题所在?

相关内容