Operating System - HP-UX
1832973 Members
2810 Online
110048 Solutions
New Discussion

Re: execute end of month..cronjob

 
SOLVED
Go to solution
mw_4
Frequent Advisor

execute end of month..cronjob

I wonder if I could run the script end of month..
Feb has 28th, and each of month has 30, 31 respectively..
who could give the answer..?
Step by step
5 REPLIES 5
Thierry Poels_1
Honored Contributor
Solution

Re: execute end of month..cronjob

Hi,

this question has already been raised a couple of times, so RTFF!!


anyway:

define a job in your crontab to run on days 28-31:

put this little test in your script:

if test `TZ=MET-24 date +%d` = 01
then
last day of month --> continue
else
not last day of month --> exit
fi


good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Michael Tully
Honored Contributor

Re: execute end of month..cronjob

Hi,

Sir A. Clay Stephenson's caljd.sh script fixes all of these date problems. Try this link.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x6e7a7d4cf554d611abdb0090277a778c,00.html
Anyone for a Mutiny ?
James R. Ferguson
Acclaimed Contributor

Re: execute end of month..cronjob

Hi:

Here's an easy way using 'cal':

# cal|awk 'NF>0 {D=$NF} END{print D}'

...IF 'D' is the same as the current day, then it's the last day of the month. This works for leap years, too, as for instance:

# cal 02 2000|awk 'NF>0 {D=$NF} END{print D}'

As for the trick using 'TZ', my European friends living around the Prime Meridian are the "lucky" ones who can use +-24 hours to exactly compute yesterday or tommorrow including the correct time.

If you look at the man pages for environ (5) you will note that offset is the value that must be added to local time to arrive at UTC (GMT). Offset has the format hh[:mm[:ss]], where (hh) is any value from 0 through 23. The optional minutes (mm) and seconds (ss) fields are a value from 0 through 59. The hour field is required. If the offset is preceded by a -, the time zone is east of the Prime Meridian. A + preceding the offset indicates that the time
one is west of the Prime Meridian.

Notice, for example, though, that at 1100 hours on July 11 in the Eastern US, you cannot produce a date *and time* exactly 24-hours ago. To affect this, the computation would need to offset 28 hours (24+4), an invalid offset.

Regards!

...JRF...
Marc Veeneman
Advisor

Re: execute end of month..cronjob

With GNU date you can test
`date -d tomorrow +%d` == 01
for end of month
mw_4
Frequent Advisor

Re: execute end of month..cronjob

I think most of you are best!!
thanks your answer again!
best regards.
Step by step