1834364 Members
2001 Online
110066 Solutions
New Discussion

cron scheduling

 
SOLVED
Go to solution
Fred Ruffet
Honored Contributor

cron scheduling

Hi all,

I want to schedule a job with cron, and have it run every first saturday of each month. To do so, I used this settings :
00 05 1-6 * 6 myjob
I expect this setting to run myjob each saturday, between the 1 and the 6 of the month, wich is equivalent to first saturday.

But it doesn't act so. It runs every saturday of the month AND every day between the 1 and 6 of the month. Is this normal behaviour ?

System is 11.00 64 bits with march 2003 quality pack patches.

>swlist -l patch | grep cron
# PHCO_21494 1.0 Cumulative cron/at/crontab patch
# PHCO_22767 1.0 cumulative crontab/at/cron patch
# PHCO_27141 1.0 cumulative crontab/at/cron patch

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
5 REPLIES 5
Sanjay_6
Honored Contributor

Re: cron scheduling

Hi Fred,

this is quite normal.

cron behaviour is cumulative. It runs on the specified days,

Try this link for s similar sitation as yours,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=535974

Hope this helps.

Regds
Steven E. Protter
Exalted Contributor

Re: cron scheduling

I think the behavior is normal.

The way to accomplish this is to run the job every Saturday.

Then use the magic http://www.hpux.ws/merjin/caljd.sh script by A. Clay to figure out if its really the first Saturday of the month and to continue execution.

Thats how I handle it.

The script is very well documented.'

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
RAC_1
Honored Contributor

Re: cron scheduling

cal|egrep -v "2004|^$"|cut -c19-20|grep -v "^$"|head -2|tail -1

Gives you the date of the first Saturday. Put this in a script. Now run your cron on every saturday. If the date is "date received by above command", then run the job, else not.

Also set cron as follows.

00 05 * * 6 myjob
Hope this helps.

Anil
There is no substitute to HARDWORK
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: cron scheduling

Patches aren't your problem this is pilot error. When you list monthdays and weekdays in your crontab the result is a logical OR rather than a logical AND.

What you need to do is run your command every Saturday and let your script itself determine if this is the 1st Saturday. Let's see, this sounds like a date problem. I wonder which tool I'll use?

In your script that fires off each Sat. do something like this:

#!/usr/bin/sh

PATH=${PATH}:/usr/local/bin
export PATH

if [[ $(caljd.sh -N) -eq 1 ]]
then
echo "1st occurence in the Month; do your thing."
else
echo "It ain't; do nothing"
fi

Invoke as caljd.sh -u for full usage and what this does.
If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: cron scheduling

Thanks,

I should have guess caljd was to mentionned on such a thread :)

Not that it's not that I don't like your script, but I find it a little bit simplier to set in cron
00 05 1-6 * * myjob
and start my script with a test on "date +%u"

Thanks again for making clear this point about cron using OR and not AND...

Regards,

Fred

--

"Reality is just a point of view." (P. K. D.)