Cron Scripts on Linux

October 29th, 2009 | Categories: Linux | Tags: , ,

OK. So this week I’ve been banging my head against the previously mentioned 5 year old bug in run-crons.

The problem is, for /etc/cron.{hourly,daily,weekly,monthly} we have the following requirements:
1) Scripts should ideally be run at a specified time.
2) Ideally the time at which the scripts run should be slightly different for each of the groupings to avoid unnecessarily loading the system and reduce potential conflicts in related scripts in different groups.
3) Scripts should never run twice within the same time period
4) If the scripts are not run for any reason in their given time period (eg. the system is offline), we want to run them at the next convenient opportunity
5) Even if the scripts are not run at their normal time for any reason, we want to run them at the normal time in the next time period
6) Because this is something very useful, we want to do this with as few resources or dependencies as possible on as many platforms as possible

So the solution the world came up with is run-crons. Which works. Most of the time.

The real headache comes because of daylight savings. Even if we don’t schedule to run in daylight savings, it leaves its mark in the form of an extra or less hour in the day that’s unexpected. This causes a problem because run-crons compares the timestamp on its “last run” spool file with the current time. Once this gets more than 24 hours old, we want to run the daily scripts again… except on daylight savings changes, when this figure is 23 or 25 hours. And we’re trying to do this in a shell script, using the most generic tools possible.

So we could use “3am” as the time to compare to – but then run-crons has to know this time. It also still brings up the issue of if the system was down for 20 hours, and comes back up at 11pm, do you want to run the cron.daily scripts for that day still? Then again at 3am the following day?

Brain damage ensues.

Frankly I’m beginning to think the world would be a better place if we did away with cron.{hourly,daily,weekly,monthly} altogether and just used cron.d. But even that still doesn’t resolve all the issues.

No comments yet.