Operating System - HP-UX
1820478 Members
2918 Online
109624 Solutions
New Discussion юеВ

Crontab entries to run every 14 days

 
SOLVED
Go to solution
Daryl Nyburg
Occasional Contributor

Crontab entries to run every 14 days

Is there a way to enter a job into crontab that will run every x number days, or every other Wednesday?
2 REPLIES 2
John Waller
Esteemed Contributor

Re: Crontab entries to run every 14 days

Daryl,

I can not think of a way to do this via crom , but you may be able to do it using at instead.

Write a script as follows and call it a dummy name e.g
/usr/local/bin/atsubmit.sh:

echo "sh /usr/local/bin/atsubmit.sh" | at now + 14 days
./actual_programme
exit 0


Now setup the initial at job, e.g.

echo "sh /usr/local/bin/atsubmit.sh" | at 2000 Aug 12.

This will now submit a job to run at 8pm on 12 August 2001 and becuase the first thing the script does is to re-submit itself it should then continue to submit itself at 8pm every 2nd Sunday (12 Aug is a Sunday)

I know this doers not answer your question but it is a work around


A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Crontab entries to run every 14 days

Hi Daryl:

There is not a way to do this directly with cron but there is a way to handle this within your script itself. The cron job is started every Wednesday but your script decides if the week is odd or even. The key to this is convert
today's date to a Julian Day. Divide that by 7 to get a julian week and mod that by 2 to get 0 or 1. You then execute if 1 and do nothing if 0 (or vice versa).

Inside your cron script:

#!/usr/bin/sh
JDAY=`/usr/loca/bin/caljd.sh/`
JWK=$((${JDAY} / 7))
IS_WK=$((${JWK} % 2))
if [ ${IS_WK} -eq 1 ]
then
echo "Do your thing"
else
echo "Do nothing"
fi

I've attached the caljd.sh script. This method will work year in/year out regardless of the number of weeks per year or days per year.

Regards, Clay
If it ain't broke, I can fix that.