Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I have several cron jobs that run:

  1. Every minute
  2. Every 5 minutes
  3. Every 15 minutes
  4. Every hour
  5. At midnight

Then at exactly 00:00 I have 5 jobs running at the same time.

I want to add another job, that I simply need to run "once a day" -- regardless of when! In fact, I want the "when" to be during the least server-load time.

How can I do this?

share|improve this question

1 Answer 1

One way to do so is this:

  1. call the intended script once an hour.
  2. On the first run of the script check for a temporary file called .runTime.
  3. If such file exists
    1. Parse it and obtain the 24-hour format time from it.
    2. If the current hour equals the parsed time
      1. Delete the .runTime file and execute the intended script
    3. If it's a different hour -- abort execution
  4. If there's no such file and the hour is 0 (midnight)
    1. compute a random hour between 0 and 23 and write it to the file
share|improve this answer

Your Answer

 
discard

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

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