cron help.

Hi,

How can i put a cron job to run every 2 weeks on sunday and monday at 10:30 AM.

Tx

One way - Sunday is day zero.

30 10 * * 0 /path/to/my/code.shl
30 10 * * 1 /path/to/my/code.shl
1 Like

Thanks for your reply.

30 10 * * 0,1 /path/to/my/code.shl can achieve the same but it will run every week.

I want to to run it every two weeks.

30 10 1,15 * 0,1 /path/to/my/code.shl

1 Like

My bad. There is no way with cron * * * * * notation to get what you want. The post above does not do that either, because over a period of years you lose runs. 365/7, 366/7 do not divide evenly.

See Perderabo's post - Can cron this?
http://www.unix.com/unix-advanced-expert-users/11562-can-cron-do-post41689.html\#post41689

1 Like

there is a little workaround for this issue, you can schedule it for everyweek in cron job, but do a check in your code whether it ran last week..
i.e
create a file \tmp\checkRun with 0 as value.

Lets assume 1 as Not ran last week and 0 as script ran last week.

checkRun=`cat "\tmp\checkRun"`
if [ checkRun=1 ] ; then
{

(Actual script goes here)
....
....
....
echo 0>"\tmp\checkRun"
}
else
{
echo 1>"\tmp\checkRun"
}

This will execute the actual login in alternate weeks.

---------- Post updated at 03:38 PM ---------- Previous update was at 02:02 PM ----------

1 Like