These scripts run a program on either the last day or last workday of the month. Dates are computed by abusing the hell out of the TZ environment variable. You can do something similar by using a cron entry like this:
58 23 * * * [ `date -d tomorrow +%d` -eq '01' ] && /myscriptbut it depends on the GNU version of date being installed.
Both scripts can be used with or without arguments. If you want to simply check the date:
if lastdom; then do something do something else fiYou can also pass a program to be run if you want to do the test and the execution all on one line:
lastdom /path/to/program arg1 arg2 ..."program" will only run if it's the last day of the month.
lastwkdom will run if:
I've also found it helpful to put a more descriptive header at the top of crontab files:
#============================================================================ # Environment: set CRON so scripts know when they're being run via cron. CRON=yes #============================================================================ # Everything on a line is separated by blanks or tabs. # #+--------------------------- Minute (0-59) #| +----------------------- Hour (0-23) #| | +----------------- Day (1-31) #| | | +------------- Month (1-12) #| | | | +--------- Day of week (0-6, 0=Sunday) #| | | | | +---- Command to be run #| | | | | | #v v v v v v #---------------------------------------------------------------------------- # Run something on the last day of the month. 8 6 28-31 * * lastdom $HOME/cron/some/script