Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

crontab

Status
Not open for further replies.

kukuluku

MIS
May 2, 2002
56
US
Hello,

How do you schedule a job to run every 1st and 3rd Sunday? With cron, if you use day of the month and day of the week, the two are ORed together. i.e.
00 02 1-7 * 0 /oracle/local/bin/rebuildndx.ksh krntest
00 02 15-21 * 0 /oracle/local/bin/rebuildndx.ksh krntest

will run every day of the month from 1 to 7 (either 1-7 or Sunday) and 15-21. And therefore won't work for my purpose.

Appreciate your input.

 
How about running on 0-6 putting a test of 'date' in 'rebuildndx.sh' and skip if not sunday? Or better: run every sunday and check for day in (1-7, 15-21) which will only lead to 2-3 failing tests per month.

If modifying 'rebuildndx.sh' isn't appropriate, you could could put an script in between which performs the test.

dont't visit my homepage:
 
Great, thanks.

I am using the following code. However, today is 11th and when I run this script, it executes both rebuldndx.ksh and analyze-gather.ksh. Can anyone tell me why? It suppose to run only between 1-7 and 15-23 of the month.

if ([ "$DATE" -ge 1 ] -a [ "$DATE" -le 7 ]) || ([ "$DATE" -ge 15 ] -a "$DATE" -le 23 ])
then
echo "Running Program..."
/oracle/local/bin/rebuildndx.ksh krntest
/oracle/local/bin/analyze-gather.ksh krntest
else
echo "Not running"
fi
 
kukuluku,

Shouldn't you have an open bracket [ before $DATE" -le 23 ]

It should read:

if ([ "$DATE" -ge 1 ] -a [ "$DATE" -le 7 ]) || ([ "$DATE" -ge 15 ] -a [ "$DATE" -le 23 ])

Hope this helps.

John
 
kukuluku,

What is the variable DATE being exported as? How is it defined? It should be:

DATE=`date +%d`

John
 
The whole scirpt:

DATE=`date +%d`
if ([ "$DATE" -ge 1 ] -a [ "$DATE" -le 7 ]) || ([ "$DATE" -ge 15 ] -a [ "$DATE" -le 23 ])
then
echo "Running Program..."
/oracle/local/bin/rebuildndx.ksh krntest
/oracle/local/bin/analyze-gather.ksh krntest
else
echo "Not running"
fi
 
Try using:

if ([ $DATE -ge 1 ] && [ $DATE -le 7 ]) || ([ $DATE -ge 15 ] && [ $DATE -le 23 ])

John
 
Try this:[tt]
if [ \( $DATE -ge 1 -a $DATE -le 7 \) -o \( $DATE -ge 15 -a $DATE -le 23 \) ][/tt]


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Good catch stefanwagner, $DATE -ge 1 should always be true, so my final guess:
if [ $DATE -le 7 -o \( $DATE -ge 15 -a $DATE -le 23 \) ]

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That works great. Thank you.

So the -a and -o can not be used with && and ||?
 
The -a and -o are argument of [ ... ] the test command.
&& and || are used by the shell or the [[ ... ]] conditional expression.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top