From: Bit Twister on
On Wed, 19 May 2010 14:20:30 -0700 (PDT), underh20 wrote:
> Hello,
>
> Our server is running Solaris 10. I need to run a cron job at 6am on
> last Sunday of every month starting from the last Sunday this month in
> May.

Subtract last day of month from current day of month.
if result greater than 6 exit, else must be last Sunday in month.

man date to fetch current day of month.

For last day of month us cal and shift. Starter snippet to play with.

set -- $(cal)
let x="$# - 1"
shift $x
echo $1
From: Bit Twister on
On Wed, 19 May 2010 21:47:02 +0000 (UTC), Bit Twister wrote:
> On Wed, 19 May 2010 14:20:30 -0700 (PDT), underh20 wrote:
>> Hello,
>>
>> Our server is running Solaris 10. I need to run a cron job at 6am on
>> last Sunday of every month starting from the last Sunday this month in
>> May.
>
> Subtract last day of month from current day of month.
> if result greater than 6 exit, else must be last Sunday in month.

Oops, that should be subtract current day from last day. :(


From: Wayne on
On 5/20/2010 10:27 AM, Guy wrote:
> underh20 wrote:
>
>> Our server is running Solaris 10.
>> I need to run a cron job at 6am on last Sunday of
>> every month starting from the last Sunday this
>> month in May.
>>
>> The current cron job below runs on every Sunday.
>> How could we modify it to run on last Sunday only
>> in each month for the next 3 years ?
>>
>> 0 6 * * 0 /usr/bin/script
>>
>
>
> The folowing will fail in the year 2032
> due to Leap Day falling upon Sunday.
>
> 0 6 22-28 2 0 /usr/bin/script
> 0 6 24-30 4,6,9,11 0 /usr/bin/script
> 0 6 25-31 1,3,5,7,8,10,12 0 /usr/bin/script
>
>
> (So you're good for the next 3 years)
>

I don't think that will work. I believe when you specify something
other than "*" for both the 3rd and 5th fields (the day of month and
day of week fields), the script will run when EITHER of the fields matches,
not when just BOTH fields match. (This always seemed odd to me, but
that's just how cron has always worked.)

--
Wayne
From: Wayne on
On 6/18/2010 2:11 PM, Guy wrote:
> Wayne wrote:
>
>> On 5/20/2010 10:27 AM, Guy wrote:
>>
>>> underh20 wrote:
>>>
>>>> Our server is running Solaris 10.
>>>> I need to run a cron job at 6am on last Sunday of
>>>> every month starting from the last Sunday this
>>>> month in May.
>>>>
>>>> The current cron job below runs on every Sunday.
>>>> How could we modify it to run on last Sunday only
>>>> in each month for the next 3 years ?
>>>>
>>>> 0 6 * * 0 /usr/bin/script
>>>>
>>>
>>>
>>> The folowing will fail in the year 2032
>>> due to Leap Day falling upon Sunday.
>>>
>>> 0 6 22-28 2 0 /usr/bin/script
>>> 0 6 24-30 4,6,9,11 0 /usr/bin/script
>>> 0 6 25-31 1,3,5,7,8,10,12 0 /usr/bin/script
>>>
>>>
>>> (So you're good for the next 3 years)
>>>
>>
>> I don't think that will work. I believe when you specify
>> something other than "*" for both the 3rd and 5th fields (the day
>> of month and day of week fields), the script will run when EITHER
>> of the fields matches, not when just BOTH fields match. (This
>> always seemed odd to me, but that's just how cron has always
>> worked.)
>>
>
>
>
> $ grep "PROOF" crontab cron.log
> crontab:* * 13-19 * 0-3 #PROOF - Job Should NOT Run
> crontab:* * 13-19 * 4-6 #PROOF - Job SHOULD Run
> cron.log:18.06.2010 13:05 #PROOF - Job SHOULD Run
> cron.log:18.06.2010 13:06 #PROOF - Job SHOULD Run
> cron.log:18.06.2010 13:07 #PROOF - Job SHOULD Run
> cron.log:18.06.2010 13:08 #PROOF - Job SHOULD Run
>
> $
>

How strange! Are you running some modified cron daemon? The Solaris 10
crontab man page shows both these should run. See example 3 for instance.
I don't have access to Solaris 10 at the moment, so I'd appreciate
a follow up post to confirm Guy's results.

--
Wayne