1825317 Members
4098 Online
109679 Solutions
New Discussion юеВ

Cron every 45 days.

 
SOLVED
Go to solution
Dan Alexander
Frequent Advisor

Cron every 45 days.

I would like cron to execute a script every 45 days. What's the easiest way to accomplish this?



2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Cron every 45 days.

Well, you could use at inside your script to schedule a subsequent job now +45 days but one break in the chain and your job never recovers.

I would schedule a run EVERY day and then let the script itself determine if this is the magic day.

#!/usr/bin/sh

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

typeset -i STAT=0
typeset -i TDAY=$(( $(caljd.sh) % 45))
if [[ ${TDAY} -eq 0 ]]
then
echo "Today is the day; do your thing"
# your commands should set ${STAT}
else
echo "Do nothing; exit"
fi
exit ${STAT}

------------------------------------------

You might want to set the -eq 0 to some value between 0 and 44 so that it starts on the correct day. Caljd.sh returns a sequential number for each day since 4713BCE. Invoke as caljd.sh -u for full usage and examples. The above example assume that you copy caljd.sh to /usr/local/bin.



If it ain't broke, I can fix that.
Dan Alexander
Frequent Advisor

Re: Cron every 45 days.

Wow. Thanks for the quick response.

I will definitely give this solution a run..

Thanks!