Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .