Lately at work I've been hacking out SQL scripts to update billing records in a mysql table before the billing run on the 1st of the month at 0000h. So I want to run them on the last day of the month, but vixie cron doesn't have a -1 value for the day of month field meaning "the last day". I could wrapperize the SQL in a perl script using Date::Simple, but I wanted to keep it simpler, so I found I could do:

SET @RunNow = if(curdate() + interval 1 day regexp '-01$', 1, 0); create temporary table ph_updates select date_format(stamp, '%Y-%m') as month, count(*) as cnt from table where 1 and @RunNow = 1 and ... group by month order by month desc ; -- all later joins to ph_updates yield 0 rows unless @RunNow is 1 ....

Since @RunNow is only true on the last day of the month, this script only ever does anything on the last day. And my /etc/crontab can look like:

50 23 * * * /usr/bin/mysql < /path/to/billing-update.sql

Also, I start my where clauses now with a 1, as in developing scripts it's useful to be able to comment out a line with a '--' at the front of the line without having to alter any other lines. If I wanted to comment out the first where condition, I'd have to alter the subsequent line. Not so if my first where condition is always true. It's a pity that I can't do the same with my select columns.