Operating System - HP-UX
1833752 Members
2540 Online
110063 Solutions
New Discussion

Re: Upload data every nine weeks?

 
SOLVED
Go to solution
Neil Edwards
Advisor

Upload data every nine weeks?

Hi,

I have a requirement to automatically upload some data files to a remote server every 9 weeks (on a Monday at 8 AM) . I can't find a combination of crontab entries that will do this. I haven't wriitten the upload script but my problem now is simply getting cron to run anything on a nine-week interval.

Any ideas out there?

Thanks in advance for your time,
Neil
It wasn't me.
6 REPLIES 6
Patrick Wallek
Honored Contributor

Re: Upload data every nine weeks?

You might want to take a look at 'at' to do the scheduling.

Once you run it the first time you could schedule it via 'at' to run again in 63 days.

Something like this:

at now + 63 days < /dir/script_to_run
Pete Randall
Outstanding Contributor

Re: Upload data every nine weeks?

See John Poff's solution using at in this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce7187dc4d7dd5118ff00090279cd0f9,00.html


Pete

Pete
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Upload data every nine weeks?

Cron on its own ain't gonna do this but we can easily run your script every Monday at 0800 and simply exit if this ain't the week.

Something like this:

#!/usr/bin/sh

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

typeset -i WK=$(( (($(caljd.sh) + 1) / 7) % 9 ))
if [[ ${WK} -eq 0 ]]
then
echo "Run Your Script"
else
echo "Do nothing"
exit 0
fi

The + 1 offset is used to make the weeks start on Sunday. We then divide by 7 to get the week number and then a mod 9. You may need to change the -eq 0 to some other value between 0 and 8 to do correct week. The advantage of this method is that it is going to work year-in, year-out without any changes.


If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Upload data every nine weeks?

Ooops, I suppose I better attach caljd.sh, I typically install it in /usr/local/bin.

No points for this, please.
If it ain't broke, I can fix that.
Neil Edwards
Advisor

Re: Upload data every nine weeks?

Hi guys and thanks for your answers. Clay's response made me realize that I could simply use `date '%U` % 9 to do the same thing and much easier. I will assign points to all.

Thanks again,
Neil
It wasn't me.
A. Clay Stephenson
Acclaimed Contributor

Re: Upload data every nine weeks?

Sorry Neil, date '+%U' will almost work and you won't know you have problems until the year changes (and some will work just fine). If the year starts on a Sunday, the week number is 1 but otherwise the week number of the days before the 1st Sunday is zero. Caljd.sh counts days sequentially from 4713BCE and avoids this problem.
If it ain't broke, I can fix that.