Hello

I do this one liner in my cron with success, maybe it suits you:

0›      5›      *›      *›      *›      TOM=$(TZ=MST-24 date +%d); [ $TOM
-eq 1 ] && logger "Ultimo dia do mês!!!"

Em qua., 1 de set. de 2021 às 09:06, Nick Holland <
n...@holland-consulting.net> escreveu:

> On 9/1/21 5:50 AM, Joel Carnat wrote:
> > Hello,
> >
> > I would like to run a command on "the last day of each month".
> >
> >   From what I understood reading the crontab(5) manpage, the simplest way
> > would be setting day-of-month to "28-31". But this would mean running
> > the command 4 times for months that have 31 days.
> >
> > Is there a simpler/better way to configure crontab(1) to run a command
> > on "the last day of month" only ?
> >
> > Thank you,
> > Joel C.
> >
>
> Just run your script every day, and first thing in the script, check to see
> if it is the last day of the month -- and quickly exit if it isn't.  Very
> cheap to do and relatively easy if you know a good trick to do it.
>
> http://holland-consulting.net/scripts/endofmonth.html
>
> Find the last day of the month:
>     $ set $(cal)
>     $ shift $(($# - 1))
>     $ echo $1
>     30
>
> Compare to today:
>     $ date "+%d"
>     1
>
> rather easy, and fairly portable.
> You could probably stuff it into a one-liner in a crontab, but I would not
> recommend it.
>
>
> Nick.
>
>

-- 
Atenciosamente,
Bruno Ferreira.

Reply via email to