1833622 Members
3752 Online
110062 Solutions
New Discussion

Re: Cron Tab

 
Montu_1
Frequent Advisor

Cron Tab

Hi,

I want to execute one script on alternate mondays.

any idea how can i configure cron ?

thanks in advance.
7 REPLIES 7
Jeff_Traigle
Honored Contributor

Re: Cron Tab

See Clay's response to the follwoing thread.

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=113380
--
Jeff Traigle
Ninad_1
Honored Contributor

Re: Cron Tab

I suggest you an alternate way as I cannot think how it can soley be deployed using cron.
In cron allow the script to run every Monday.
And in the script check if this is a say even Monday or a odd Monday using date +%V or %W whichever is suitable and allow the script to run if its the alternate Monday.

Regards,
Ninad
OldSchool
Honored Contributor

Re: Cron Tab

There isn't any way within cron itself. You will need to run the script every Monday, and then, within the script, determine if it is a Monday that it should run on.

There is a script (cal_jd.sh) and perl version of same (cal_jd.pl) around here somewhere that may assist you in this
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Tab

The idea is to run your script every Monday and then let it decide if it should execute or not.


Install the attached utility, caljd.sh, in a directory (e.g. /usr/local/bin) and then your cron'ed script should look something like this:

#!/usr/bin/sh

typeset -i STAT=0
export PATH=${PATH}:/usr/bin:/usr/local/bin

typeset -i WK=$(( ($(caljd.sh) / 7) % 2 ))
if [[ ${WK} -eq 0 ]] # depending upon the week you want to start this might need to be -eq 1
then
echo "Do your thing"
fi
exit ${STAT}


This will work across year boundaries, leap years, whatever because caljd.sh in this form returns a sequential number of days since 1-Jan 4004 BCE. Invoke as caljd.sh -u for full usage and examples.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Tab

Drat, Bishop Usher confused me. I meant to say that caljd.sh counts days sequentially from 4713 BCE.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Cron Tab

I really should make a small correction so that the weeks actually begin on the more traditional Sunday (although in your case, it won't make any real difference). Adding 1 to the Julian days has that effect.

typeset -i WK=$(( (($(caljd.sh) + 1) / 7) % 2 ))
If it ain't broke, I can fix that.
Montu_1
Frequent Advisor

Re: Cron Tab

Hi All,

Thanks for your valued reply,

sorry for delay in points!.