Get the last day of the month
Get the last day of a month with GNU date by adding one month to the first day and subtracting one day. Adding a month to the 31st lands in the wrong month.
A job runs on the last day of each month, and the number of days changes with the month and with leap years.
date -d '2026-01-31 next month -1 day' +%F
d=2026-01-31
date -d "${d%-*}-01 +1 month -1 day" +%F
date -d "2028-02-01 +1 month -1 day" +%F2026-03-02
2026-01-31
2028-02-29Adding a month to the 31st of January gives "31 February", which GNU date normalizes to the third of March, and one day before that is the second, so the first line is wrong. Starting from the first day of the month avoids that: the first of next month minus one day is always the last of this one. The date arithmetic follows the relative items rules. The last run shows the leap year, where February 2028 ends on the 29th.
GNU date only. For a cron job, test the day in the command instead: [ "$(date -d tomorrow +%d)" = 01 ] && run-the-job, since the cron time fields cannot express "last day". Remember the percent signs in a crontab need escaping.