2

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.

2 Answers2

4

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.

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.

guntbert
  • 13,475