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.

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.

share|improve this question
    
You will need to keep the machine running in order for the job to be run... –  nicorellius Jul 10 '10 at 23:05
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.