Operating System - HP-UX
1754420 Members
2687 Online
108813 Solutions
New Discussion юеВ

Cron to run every other Sunday

 
Susan Dietz
Occasional Advisor

Cron to run every other Sunday

HP-UX 10.20

Does anyone know how to code a cron to run every other Sunday at midnight?

Thanks...Susan
5 REPLIES 5
Cheryl Griffin
Honored Contributor

Re: Cron to run every other Sunday

If you set it to run Sundays, it would run every Sunday. So as an alternate you would have to set it up to run specific days instead, meaning May 4, May 18, June 1, etc.
"Downtime is a Crime."
Helen French
Honored Contributor

Re: Cron to run every other Sunday

Nice scripts and discussion here (Check Clay's script, I 've used it and found working very well):

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce7187dc4d7dd5118ff00090279cd0f9,00.html
Life is a promise, fulfill it!
Jeff Schussele
Honored Contributor

Re: Cron to run every other Sunday

Hi Susan,

This may be one of those situations where at is a better alternative than cron.

Investigate setting this job up as an at job set to start the next Sunday you want it to run. Then as the last task of the at job have it run another at scheduled 14 days later.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
john korterman
Honored Contributor

Re: Cron to run every other Sunday

Hi Susan,
a simple way is to first schedule the job to run every Sunday in crontab, e.g.:
10 15 * * 0 /usr/local/bin/sunday.sh

Then let the script decide which Sundays it should run. Use the "return day number command" for figuring that out, e.g.:
# date +%j
114

as there are 7 days in a week, every other Sunday would all be either odd day numbers or even day numbers.

Then let the script exit on either an odd or an even day number. Example:

#!/usr/bin/sh
#
# Check the day number of the year
#
typeset -i DAY_NUM=$( date +%j )
HALF=$(( $DAY_NUM \/ 2 ))
DOUBLE=$(( $HALF \* 2 ))
if [ "$DAY_NUM" != "$DOUBLE" ]
then
echo odd day
#exit
else
echo even day
# exit
fi

regards,
John K.
it would be nice if you always got a second chance
Michael Steele_2
Honored Contributor

Re: Cron to run every other Sunday

Try using the day of the week crontab setting in conjunction with a stored interger that increases by one every time called and tests for even or odd with the modulus operator, '%'.

Call the script every Sunday but ignore the odd Sundays.

Store the integer in a file.

Here's an 'untested' outline.

0 0 * * 1 /home/bill/scripts/sunday_script



#!/usr/bin/ksh

day=$(cat /home/bill/integer_file)

remainder=even_days%2

if [ $remainser=0 ]
then
execute script
if

even_days=$(($even_day+1))
echo $even_days>/home/bill/integer_file

(* Fool around with it. *)
Support Fatherhood - Stop Family Law