Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Seems like such a simple question, but I can't find an answer to:

Cron is scheduled to run daily, say at midnight. If my system is offline during that period of time and I turn it on the next day, cron won't run my jobs on boot. Is there any way to change this behaviour, say by making all backlogged jobs run at once on boot?

share|improve this question

migrated from stackoverflow.com Oct 1 '10 at 7:42

This question came from our site for professional and enthusiast programmers.

4 Answers 4

You might need to add a separate entry:

@reboot /path/to/job

share|improve this answer
    
Is it possible to run once on reboot, but only a maximum of once a day? Thanks –  david Sep 29 '10 at 16:09
    
I suggest you do a verification on the script that will check if the script has already been executed for the day. For this, all I can think of is using the date command and check it against a file wherein another date is written. It will be the same file which the script will overwrite the current value if date is not the same (after execution) –  Ruel Sep 29 '10 at 16:17

I suppose you need this. Apparently, you can schedule jobs to run only once a day using /etc/cron.daily.

share|improve this answer

Not with vixiecron, not exactly.

You probably want anacron, which was specifically created to cover the "offline" gap in cron. Anacron is designed to work with cron, but you could use a complete cron replacement instead. FCron is one which will take system down time in to account.

share|improve this answer
    
Thanks, I'm currently using dcron, but this is probably what I need. –  david Sep 29 '10 at 16:24
    
This is the right way to do it. –  Matt Joiner Sep 29 '10 at 22:47

I'd say that in a robust system, run the cron jobs more often than you really want, and have them check if they need to do any work, and only do it if necessary.

THis is often a good idea anyway, as a previous run may have failed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.