Tue, 04 Nov 2008
Running cron fortnightly: round-up
It's a few days on from my original post, so I thought I'd give a summary of people's ideas. Just to remind you of the aim of the exercise, it's to get a cron job to run every fortnight, without using the 'date' command.
So, here are the ideas we've had:
- Run on the 1st and 15th of every month: This isn't really a solution to the problem, as it's not truly fortnightly.
- Writing a cronjob that rewrites the crontab each week: This is an interesting one, and didn't occur to me at all. It's also insane and, as John said when he suggested it, probably complex enough that you'd have to do it in each individual script for which you wanted this.
- Touching a file to determine which week we're in: This would work, but has the disadvantage of having to put a file somewhere, when there's not really a well defined place to do it.
Well, in light of the above ideas, my solution might be slightly cheaty.
It depends on a Debian (or, presumably, Ubuntu system), as it takes
advantage of /etc/cron.weekly. Essentially you write a script that live
in /etc/cron.weekly and symlinks other scripts in and out of /etc/cron.weekly.
These scripts could be stored in, for example, /etc/cron.fortnightly. It would
scan through there and symlink in any that weren't in /etc/cron.weekly and
remove existing symlinks to /etc/cron.fortnightly scripts.
This has the advantages of:
- Being fortnightly,
- Not being epic hax,
- Having a well-defined place for all of the files involved to live, and
- Not requiring special setup for each cronjob or script.
Of course, we should all just use 'date'...
EDIT: benji has noted that /etc/cron.weekly is by no means a Debian-specific feature. SUSE has it. Warn your distributor now.
Posted: Tue, 04 Nov 2008 21:56 | | Comments: 4 |