0

I wanted to schedule a daily task using anacron. After some reading I added the below line to /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

This works (script executes as expected) but is done hourly whilst it should be done once a day. Here is the output of 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

It seemed to me that anacron is actually ran by cron itself and on system start up, but to my surprise there is an anacron service and associated anacron timer which triggeres every hour. When I stop the service and the timer however the job will not run at all. Any suggestions as to why the daily period is not respected?

Thanks

Organic Marble
  • 23,641
  • 15
  • 70
  • 122

2 Answers2

2

A better approach for me is to drop an executable script in /etc/cron.daily/ and you have no more worries.

2

The man page for anacrontab states

The period_name can only be set to monthly at the present time.

so your daily will not work and is causing the error message anacron: /etc/anacrontab: Unknown named period on line 14, skipping

Sourced from comments at Tell me where is mistake in anacron task?

Organic Marble
  • 23,641
  • 15
  • 70
  • 122