2

Let's say I do this:

0 0 0 * * somejob

Will this run on a set date, and if my computer is not no at that date will it skip that week?

Let's say I set this job right now. And then my computer is turned off 5 days from know for the whole day.

Basically I need something to run every week, but my computer may not be on 24/7.

Zombies
  • 3,972

2 Answers2

4

Yep, cron will only run a job scheduled for a specific time if the computer is on at that time. The way it works is that each minute, it checks all scheduled cron jobs to see if their time fields match the current minute, and if so, it runs the job. If not, it gets skipped. There's no concept of "saving" the execution of a job for a later time.

What you could do, for your situation, is use a marker file to indicate the last time the job was run. Create a little script or program that looks like this (this is pseudo-Bash syntax):

if (marker file was last modified > 1 week ago); then
    run the job
    touch marker file
fi

and you can set that script as a cron job to run every day, every hour, or even every minute - as often as you need to ensure that it will run at least once each week during the time you have your computer on.

David Z
  • 6,785
2

Anacron is likely what you're looking for:

Anacron is a periodic command scheduler. It executes commands atintervals specified in days. Unlike cron, it does not assume that thesystem is running continuously.

notpeter
  • 1,207