You are not logged in.

#1 2011-05-14 11:19:34

cyberius
Member
From: Germany
Registered: 2008-08-30
Posts: 97

[SOLVED] Run cronjob asynchronous, but preferably at a given time?

Hello!

How can I add a cronjob, which should run preferably at a specified time (like every day 5 o clock in the morning), but if the computer is off at that time, it will run some other time?

To make it run every day at 5 o clock, I can use "00 05 * * * /home/tom/_scripts/bkp.sh". But if the computer is off at that time, it wont run that day.

So to make it run asynchronous, I should use @daily.

How can I combine those two options?

Last edited by cyberius (2011-05-14 18:18:56)

Offline

#2 2011-05-14 11:34:11

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [SOLVED] Run cronjob asynchronous, but preferably at a given time?

What you could do, is have that script save a status file in /tmp. Then add a job in /etc/cron.daily that first checks for that status file, if it doesn't find it then run the job/script.


ᶘ ᵒᴥᵒᶅ

Offline

#3 2011-05-14 12:11:24

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] Run cronjob asynchronous, but preferably at a given time?

Xyne has written cronwhip, that I find useful to run missed cron tasks, http://aur.archlinux.org/packages.php?ID=21079.  It can be added to '/etc/rc.local'  to pick up missed cronjobs when you start the computer.  My daily backup is set to run at 06:00 AM.  I use cronwhip to make sure that the backup is never missed if the computer wasn't awake or I wasn't powered up at that time.

For something more like 'cron', 'anacron' may be what you're looking for: http://en.wikipedia.org/wiki/Anacron.

Offline

#4 2011-05-14 17:42:08

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Run cronjob asynchronous, but preferably at a given time?

Using dcron:

* 07-15 * * *   ID=example     FREQ=1d/15m     /home/firecat53/scripts/example.sh

This will run daily sometime between 0700 and 1500, with at least 1 day from the last time it was run. Also, if the job fails to complete and returns error code 11 (I think) it will retry every 15 minutes.

Hope that helps!
Scott

Last edited by firecat53 (2011-05-14 17:42:35)

Offline

#5 2011-05-14 18:14:35

cyberius
Member
From: Germany
Registered: 2008-08-30
Posts: 97

Re: [SOLVED] Run cronjob asynchronous, but preferably at a given time?

Thank you all!

I installed cronwhip, it should do the trick.

@firecat53
So does FREQ=1d/15m run the script at least once a day or just with a minimum delay of one day (but won't run it when the machine is turned off from 8-15 hours) ?
Excuse me if I didnt understand you fully, but english isnt my native language smile

Last edited by cyberius (2011-05-14 18:22:29)

Offline

#6 2011-05-14 18:47:43

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED] Run cronjob asynchronous, but preferably at a given time?

As I understand it, FREQ=1d has the same effect as @daily. I'm not sure with either one you can actually set a 'preferred' time, unless it's a time range. For example, if you have @daily set and your backup runs at 0500 on Sunday, then Monday you don't turn on the computer until 1600 (4pm) so the backup runs at 4pm, then Tuesday it wouldn't run again until sometime after 4pm, because it hasn't been a full day yet. I don't believe (anyone feel free to correct me if I'm wrong here!!) that you could do a normal (d)cron job that would would run on Monday at 4 (because the machine's not on) and then again Tuesday morning at 5am when you'd really prefer it to run. The time range (07-15 from my example above) does give some more flexibility, but I don't think exactly what you're looking for.

Scott

Offline

Board footer

Powered by FluxBB