1

I am using Ubuntu 12.04 for an embedded project. I need cron jobs to execute only at their specified time, because time may be stepped forwards (resulting in a missed job) but those jobs should be skipped. While testing this, even when I place my crontabs into /etc/cron.d, and for example schedule the job for 13:15, set system time to 13:25, the job will execute at ~13:26. I do not want to execute missed jobs, they should be ignored (according to the research I've done, this is "normal" cron behavior). Any suggestions on how to remove anacron and just keep plain old cron?

Thanks.

  • Uninstalling anacron may not be safe. Please see askubuntu.com/q/43576/8973 for more details. – papukaija Jul 10 '13 at 19:44
  • @papukaija that may be true, is there any way to NOT execute missed jobs though? I thought placing them into /etc/cron.d would bypass anacron, but this is not the case – user1345 Jul 10 '13 at 19:52
1

I see no reason why removing anacron would be problematic. The answer mentioned by papukaija doesn't contain any warnings either. Especially since missing jobs is exactly what you want when time is stepped.

The package description says:

You should install this program if your system isn't powered on 24 hours a day to make sure the maintenance jobs of other Debian packages are executed each day.

So simply remove it with sudo apt-get remove anacron (Don't use purge so the config files are kept)

One problem remains (as you noticed) - cron sees time steps smaller than three hours as results from something like Daylight Saving Time and still executes missed jobs.

Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Conversely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run.

Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately

Your possible way around lies in the fact that only jobs with exact execution time are affected.

Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wildcards are run based on the new time immediately.

So if you want to execute some job every 3 hours you would write a line like

25  */3 * * * root /path/so/some/file

A completely different approach (if you want those jobs run at most once) would be to employ at.

| improve this answer | |
  • Strangely, missed jobs are still executed – user1345 Jul 10 '13 at 20:46
  • @user1345 I updated my answer to address the problem of small time steps. – guntbert Jul 11 '13 at 7:55
  • The problem with <at> is that I believe it uses a lot of system resources. You do explain the issue well though and this will help me solve/get around the problem. Thanks! – user1345 Jul 11 '13 at 13:04
  • I think you mixed up at and sleep: please see The Linux Documentation Project on this topic. – guntbert Jul 11 '13 at 14:06
3

Uninstalling anacron also uninstalls the desktop. In other words, Ubuntu assumes a system without anacron to be a server. If that is a problem for you, then you can try removing execute permissions from the anacron binary:

sudo chmod a-x /usr/sbin/anacron
sudo chmod a-x /etc/init.d/anacron

This is because /etc/crontab checks for the presence of anacron by verifying whether /usr/sbin/anacron is executable, and if it is not the daily, weekly and monthly jobs are run synchronously.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.