I want to run a cronjob once every day on a machine that doesn't run all the time, but runs at least once a day for a couple of hours. The problem with a cronjob is, that I have to give it the exact time, when it is supposed to run, but my machine may not be running at this particular time. I know there is an option to cron that says "do this, when booting" but my machine usually isn't rebooted, but I leave it in standby. Put differently, I want to execute something once a day, but I can't give an exact time. Is there a solution to this?

link|improve this question
feedback

3 Answers

up vote 4 down vote accepted

You want something like anacron:

anacron is a computer program that performs periodic command scheduling which is traditionally done by cron, but without assuming that the system is running continuously. Thus, it can be used to control the execution of daily, weekly, and monthly jobs (or anything with a period of n days) on systems that don't run 24 hours a day.

Available as packages in most Linux distributions. There's probably also a port for MS Windows...

link|improve this answer
This is the answer. Perfect – sinni800 Feb 2 '11 at 11:44
feedback

How you tried @daily?

Example:

@daily $HOME/task/run.sh
link|improve this answer
That does not solve the problem. @daily is just an alias for a certain time once a day (usually midnight). – sleske Feb 2 '11 at 9:41
Yeah you are right :( Also, please check answer from sleske, it seems like helpful. – jsalonen Feb 2 '11 at 9:49
feedback

You could invoke the job from a startup script in /etc/rc2.d which compares today's date with one saved in a file and then updates that file.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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