Re: howto tell cron run last day of month
On 03-Jan-01 Nate Duehr wrote:
> Would midnight on the 1st work? Just a thought.
>
> There's no situations I can think of where the first of the month
> doesn't exist in most locales, since daylight savings changes
> officially
> at 2 AM in places that do that.
>
> (like here... grrr)
>
> On Tue, Oct 17, 2000 at 06:12:21PM +0200, Jaume Teixi wrote:
>> I run a cron script 27-31
>> then inside the script i need to check if it this last day of month
>>
>> how to check this ?
>>
>> thanks,
>> jaume.
Try this for size:
# `cal 1 2001 | grep -v '[A-Z]' | grep '[0-9]$' \
| awk '{print "export LAST="$(NF)}'`
# echo $LAST
31
# `cal 2 2001 | grep -v '[A-Z]' | grep '[0-9]$' \
| awk '{print "export LAST="$(NF)}'`
# echo $LAST
28
You can get the current day DD, the current month MM
and the current year YYYY from the date command:
# DD=`date +%d` ; echo $DD
04
# MM=`date +%m` ; echo $MM
01
# YYYY=`date +%Y` ; echo $YYYY
2001
# `cal $MM $YYYY | grep -v '[A-Z]' | grep '[0-9]$' \
| awk '{print "export LAST="$(NF)}'`
# echo $LAST
31
Then you can carry out whatever comparison you want between
$DD and $LAST (e.g. if there's something which has to be
done 4 days before the end of the month ... ).
I once used to get paid on "the Friday preceding the last
Saturday of the month" -- now that's the _next_ exercise
for the reader!
Ted.
--------------------------------------------------------------------
A Topical Thought: It is better to arrive, than to travel hopefully
E-Mail: (Ted Harding) <Ted.Harding@nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 284 7749
Date: 04-Jan-01 Time: 10:25:57
------------------------------ XFMail ------------------------------
Reply to: