Operating System - HP-UX
1833163 Members
3399 Online
110051 Solutions
New Discussion

Scheduling a backup to run every 3 weeks

 
SOLVED
Go to solution
ChadT
Occasional Advisor

Scheduling a backup to run every 3 weeks

I am currently attempting to set up to run a backup script every 3 saturdays. Cron does not allow me to do this in one job. I would need to schedule 1 job for every specific date I want it to run resulting in a bunch of backup jobs. My goal is to set up one job to run one time every 3 weeks. Any help would be appreciated.

Thank you.
6 REPLIES 6
spex
Honored Contributor
Solution

Re: Scheduling a backup to run every 3 weeks

Hi,

Schedule this to run every Saturday at the desired time:

[ $(( $(date +%V)%3 )) -eq 0 ] &&

PCS
ChadT
Occasional Advisor

Re: Scheduling a backup to run every 3 weeks

Thank you for the prompt response. I can not get that to work...could you elaborate on what it is doing? THanks again.
Steven E. Protter
Exalted Contributor

Re: Scheduling a backup to run every 3 weeks

Shalom,

http://www.hpux.ws/merijn/caldj.sh
http://www.hpux.ws/merijn/caldj.pl

Run the job as a weekly cron job and use one of those two honeys to determine if its the third week of the month and any real work needs to be done.

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
A. Clay Stephenson
Acclaimed Contributor

Re: Scheduling a backup to run every 3 weeks

Date '+%V' and/or date '+%W' get a little squirrelly at the beginning and end of year.
Here's a solution that works every time across year boundaries:

Download the attached caljd.sh; make it execuitable; and install it in a convenient directory, e.g. /usr/local/bin.

Now run your cron'ed script every Saturday and the script itself decides if this is the 3rd Saturday:

-------------------------------------------
#!/usr/bin/sh

export PATH=${PATH}:/usr/bin:/usr/local/bin
typeset -i STAT=0
typeset -i STARTWK=1 # set to 0, 1, or 2
# --------------- depending upon when you
# --------------- want to start

if [[ $(( (($(caljd.sh) + 1) / 7) % 3 )) -eq ${STARTWK} ]]
then
echo "Do your thing and set the exit status"
STAT=${?}
fi
exit ${STAT}

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

By adding 1 to the current Julian Day, the weeks start on Sunday then we simply integer divide by 7 to get the week number and then do a MOD 3. Julian Days simply count sequentially from 4713BCE and don't care about year boundaries at all. Invoke as caljd.sh -u for full usage and examples.
If it ain't broke, I can fix that.
ChadT
Occasional Advisor

Re: Scheduling a backup to run every 3 weeks

Looks like this will do the trick...thank you very much. I wish I could award more points.

Thanks again.
ChadT
Occasional Advisor

Re: Scheduling a backup to run every 3 weeks

The responses above have resolved my problem... I will be using the script provided elsewhere as well. THanks guys.