Save it somewhere, e.g. /usr/local/bin/is_last_day_of_month and make it executable. Then in your crontab (to run at 1:13 am):

Code:

13 1 28-31 * * /usr/local/bin/is_last_day_of_month && yourcommand

colucix

08-14-2008 10:01 AM

Another idea is a test based on the cal command, as shown in this thread.

FormalLogic

08-15-2008 01:42 AM

Thanks Guys!!!

Thanks guys, answer is perfect,
This thread just shows how much I still need to learn. i'm a sysadmin/programmer so I'm learning different date syntax all the time (i've got to remember MySql/Php/Linux/C/God Knows What else) It's a little daunting sometimes. But I'll just do what i always do: wing it! As you've probably guessed formal logic is a euphamisim for "Don't know what the hell i'm doing"

colucix

08-15-2008 03:15 AM

I've just noticed a little bug in the code suggested by matthewg42. In line 10:

Code:

tomorrow_month=$(date -d "$test_date + 1 day" +%m)

you have to strip out the plus sign between $test_date and "1 day". The syntax to add days, hours, and so on, is simply

Code:

date -d "$test_date 1 day 3 hours"

that is you can put one or more time specifications with different units, but without the + sign. To subtract an amount of time, use the word "ago" in the time specification:

Code:

date -d "$test_date 4 days ago"

archtoad6

12-08-2008 07:05 AM

Messy.

I've just re-read man:crontab(5) & man:cron(8) & I'm surprised there is no "Last of Month" feature. IMO, this is a bug.

If you run your script at 1:13 am, as suggested, won't you be doing your update before the beginning of business? I would expect that anything that needs to be done on the last day of the month needs to be done after the close of business. If that is the case, why not run your script at 1:13 am on the 1st of the month.