Re: Run a command on "last day of month"
Or, since last day of the month never occurs before the 28th, you could run the script only on days which might be the last of the month, Also, since crontab does support a month column, you could have three crontab entries: one for months with 31 days (month: 1,3,5,7,8,10,12), another for months with 30 days (month:4,6,9,11), and another for February. Then, you could either neglect the 29th of February, or you could have your script do a year test (and the next year evenly divisible by 4 which is not a leap year is 2100). FYI, -- Raul On Wed, Sep 1, 2021 at 8:04 AM Nick Holland wrote: > > 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. >
Re: Run a command on "last day of month"
Hi, Adam Paulukanis wrote on Wed, Sep 01, 2021 at 04:39:54PM +0200: > if today is the last day of the month, tomorrow will be 1st. That is a non-portable assumption and a trap that many people seem to fall into. For example, in the shire calendar, 1 Afterlithe (~= July) is the fourth day after 30 Forelithe (which always is the last day of Forelithe ~= June) in some years, and the fifth day after in other years, but never the first, second, or third. Similarly, 1 Afteryule (~= January) is the third day after 30 Forejule (the last day in Foreyule ~= December). That also implies that January 1 is *never* the first day of the year, and that the last day of the last month of a year is *never* the last day of that year. Localization is an extremely hard and complex task. For that reason, OpenBSD believes the C library is the wrong place to attempt to provide such functionality. The same applies to general-purpose command line tools like date(1), ls(1), and cron(8). The price to pay in terms of complexity, and hence ultimately in bugs, would be excessive. Yours, Ingo
Re: Run a command on "last day of month"
On Wed, Sep 01, 2021 at 04:39:54PM +0200, Adam Paulukanis wrote: | On Wed, 1 Sept 2021 at 16:32, Christian Weisgerber wrote: | > | > Goetz Schultz: | > | > > I would go the other way and check tomorrows date. If it is "01", then I | > > know today is the last of this month: | > > | > > date --date="tomorrow" +%d | > > 02 | > | > That's not OpenBSD. | > | > $ date --date="tomorrow" +%d | > date: unknown option -- - | > usage: date [-aju] [-f pformat] [-r seconds] | > [-z output_zone] [+format] [[cc]yy]mm]dd]HH]MM[.SS]] | > | | | Not sure if it is OpenBSD. I am on Darwin right now | | $ date -v+1d +%d # if today is the last day of the month, tomorrow will be 1st. This will work on OpenBSD: [ $(date -r $(($(date +%s) + 86400)) +%e) -eq 1 ] || exit 0 Although you'll have to be cautious with tricks like these to run this only between 01:00 and 23:00 if your system runs with a timezone that has daylight savings time. Cheers, Paul 'WEiRD' de Weerd -- >[<++>-]<+++.>+++[<-->-]<.>+++[<+ +++>-]<.>++[<>-]<+.--.[-] http://www.weirdnet.nl/
Re: Run a command on "last day of month"
On Wed, 1 Sept 2021 at 16:39, Adam Paulukanis wrote: > > On Wed, 1 Sept 2021 at 16:32, Christian Weisgerber wrote: > > > > Goetz Schultz: > > > > > I would go the other way and check tomorrows date. If it is "01", then I > > > know today is the last of this month: > > > > > > date --date="tomorrow" +%d > > > 02 > > > > That's not OpenBSD. > > > > $ date --date="tomorrow" +%d > > date: unknown option -- - > > usage: date [-aju] [-f pformat] [-r seconds] > > [-z output_zone] [+format] [[cc]yy]mm]dd]HH]MM[.SS]] > > > > > Not sure if it is OpenBSD. I am on Darwin right now Nevermind. It seems OpenBSD does not have it. > > $ date -v+1d +%d # if today is the last day of the month, tomorrow will be > 1st.
Re: Run a command on "last day of month"
On Wed, 1 Sept 2021 at 16:32, Christian Weisgerber wrote: > > Goetz Schultz: > > > I would go the other way and check tomorrows date. If it is "01", then I > > know today is the last of this month: > > > > date --date="tomorrow" +%d > > 02 > > That's not OpenBSD. > > $ date --date="tomorrow" +%d > date: unknown option -- - > usage: date [-aju] [-f pformat] [-r seconds] > [-z output_zone] [+format] [[cc]yy]mm]dd]HH]MM[.SS]] > Not sure if it is OpenBSD. I am on Darwin right now $ date -v+1d +%d # if today is the last day of the month, tomorrow will be 1st.
Re: Run a command on "last day of month"
Goetz Schultz: > I would go the other way and check tomorrows date. If it is "01", then I > know today is the last of this month: > > date --date="tomorrow" +%d > 02 That's not OpenBSD. $ date --date="tomorrow" +%d date: unknown option -- - usage: date [-aju] [-f pformat] [-r seconds] [-z output_zone] [+format] [[cc]yy]mm]dd]HH]MM[.SS]] -- Christian "naddy" Weisgerber na...@mips.inka.de
Re: Run a command on "last day of month"
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.
Re: Run a command on "last day of month"
On 01/09/2021 13:02, Nick Holland wrote: 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. I would go the other way and check tomorrows date. If it is "01", then I know today is the last of this month: date --date="tomorrow" +%d 02 -- Thanks and regards Goetz R Schultz Quis custodiet ipsos custodes? >8-- /"\ \ / ASCII Ribbon Campaign X against HTML e-mail / \ >8-- >8-- /"\ \ / ASCII Ribbon Campaign X against HTML e-mail / \ This message is transmitted on 100% recycled electrons. >8-- Please support these causes: https://you.38degrees.org.uk/petitions/rescue-lanes-on-multi-lane-roads https://www.justgiving.com/crowdfunding/fylde-cfr-team 8<-- Unsigned message - no responsibillity that content is not altered
Re: Run a command on "last day of month"
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.
Re: Run a command on "last day of month"
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 ? cron has no way to do this adding a non-portable extension doesn't really make sense the easiest way is to have your script run then (or every day), and make a more detailed check inside the script. this pattern is very common...
Run a command on "last day of month"
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.