Cron 没有启动作业?

Cron 没有启动作业?

这是 Ubuntu 18.04 的非标准安装,Ubuntu 18.04 是基于 ELAR Arm 的 Ubuntu 发行版,支持 RockChip 主板(例如 Asus tinkerboard)。问题和解决方案可能不适用于您的情况或其他 Mainline Ubunutu 发行版。

由于某些奇怪的未知原因,我有一个 cron 作业没有运行,所以我开始四处搜索,并在 NixCraft 网站上找到了一个提示,上面说我可能需要使用 systemctl 启用 cron。好的,有一个例子,所以我试了一下。我进行了身份验证,但仍然失败。

# systemctl enable cron.service
Synchronizing state of cron.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable cron

看起来 cron 服务已启用,对吧?嗯,那么在启动时@reboot /usr/bin/motion -b应该会运行,但它没有运行。我查看了一下,/var/log/syslog 发现有一个地方 cron 似乎失败了,但我不确定下一步该怎么做。

Jun 17 04:08:37 ELAR-Systems systemd[1]: Reloading.
Jun 17 04:08:37 ELAR-Systems systemd[1]: message repeated 2 times: [ Reloading.]
Jun 17 04:09:01 ELAR-Systems cron[347]: Authentication token is no longer valid; new one required
Jun 17 04:09:01 ELAR-Systems CRON[1629]: Authentication token is no longer valid; new one required

想知道如何解决这个问题....

答案1

在 redhat 论坛上,我看到一个类似的、但可能不相关的帖子,指出我必须更改我的用户名才能重新进行身份验证。呃,好的......

# chage -l root
Last password change                    : password must be changed
Password expires                    : password must be changed
Password inactive                   : password must be changed
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 99999
Number of days of warning before password expires   : 7

root@ELAR-Systems:# passwd root 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

root@ELAR-Systems:# chage -l root
Last password change                    : Jun 16, 2018
Password expires                    : never
Password inactive                   : never
Account expires                     : never
Minimum number of days between password change      : 0
Maximum number of days between password change      : 99999
Number of days of warning before password expires   : 7

然后……问题就解决了。管它呢,反正还是发这个吧。再说一遍,这个解决方案可能不适用于主流 Ubuntu 发行版。

我发现 cron 没有启用,并且需要 root 用户来验证 cron 服务。 之后,我的 cron 作业便正常运行。

答案2

与同事一起研究了这个问题,发现在他的 Ubuntu 16 上可以运行,但在 18 上不运行。仔细查看后发现,他使用的 sudo nano /etc/crontab是 而不是sudo crontab

我把命令在需要的时间运行...

30 13 * * *    root     shutdown -h now

一切都运行正常 — — 即使 Linux 没有登录用户。

相关内容