我想使用 anacron 安排日常任务。经过一番阅读,我在 /etc/anacrontab 中添加了以下行:
@daily 10 price_scrape /home/pawel/Project_Inflation/run.sh >> /home/pawel/Project_Inflation/log/task_log 2>> /home/pawel/Project_Inflation/log/error_log
这有效(脚本按预期执行),但每小时完成一次,而应该每天完成一次。这是输出grep 'cron' /var/log/syslog
:
Jun 27 15:02:24 pawel-ubuntu anacron[399]: Anacron 2.3 started on 2019-06-27
Jun 27 15:02:24 pawel-ubuntu anacron[399]: anacron: /etc/anacrontab: Unknown named period on line 14, skipping
Jun 27 15:02:24 pawel-ubuntu anacron[399]: /etc/anacrontab: Unknown named period on line 14, skipping
Jun 27 15:02:24 pawel-ubuntu anacron[399]: Will run job `price_scrape' in 10 min.
Jun 27 15:02:24 pawel-ubuntu anacron[399]: Jobs will be executed sequentially
Jun 27 15:12:24 pawel-ubuntu anacron[399]: Job `price_scrape' started
Jun 27 15:12:53 pawel-ubuntu anacron[399]: Job `price_scrape' terminated
Jun 27 15:12:53 pawel-ubuntu anacron[399]: Normal exit (1 job run)
Jun 27 15:17:01 pawel-ubuntu CRON[721]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 27 16:02:24 pawel-ubuntu systemd[1]: Started Run anacron jobs.
Jun 27 16:02:24 pawel-ubuntu anacron[2762]: Anacron 2.3 started on 2019-06-27
Jun 27 16:02:24 pawel-ubuntu anacron[2762]: /etc/anacrontab: Unknown named period on line 14, skipping
Jun 27 16:02:24 pawel-ubuntu anacron[2762]: anacron: /etc/anacrontab: Unknown named period on line 14, skipping
Jun 27 16:02:24 pawel-ubuntu anacron[2762]: Will run job `price_scrape' in 10 min.
Jun 27 16:02:24 pawel-ubuntu anacron[2762]: Jobs will be executed sequentially
Jun 27 16:12:24 pawel-ubuntu anacron[2762]: Job `price_scrape' started
Jun 27 16:12:53 pawel-ubuntu anacron[2762]: Job `price_scrape' terminated
在我看来,anacron 实际上是由 cron 本身运行并在系统启动时运行的,但令我惊讶的是,有一个 anacron 服务和相关的 anacron 计时器每小时触发一次。但是,当我停止服务和计时器时,该作业根本不会运行。关于为什么不尊重每日时间的任何建议?
谢谢