------------------------------------------------------------------------------- Crontab recipe Hints WARNING: '%' is a special character in crontabs! -- escape it '\%' This is especially important if you use "date" in a cron script. ------------------------------------------------------------------------------- Who to mail Add MAILTO="user@email.domain" to have crontab mail to your specific address ------------------------------------------------------------------------------- Run first Saturday of Month 0 0 1-7 * * [ `date '+\%u'` -eq 6 ] && CMD OR swaping what tests what 0 0 * * 6 [ `date '+\%d'` -le 7 ] && CMD also equivelent to 0 0 * * 6 [ `date '+\%e'` -le 7 ] && CMD NOTE solaris cron needs the single quotes for it to work properly This does NOT work.... 0 0 1-7 6 CMD will acutally run the command on days 1 to 7 AND Saturdays!!! It is not just the first saturday of the month. ------------------------------------------------------------------------------- Run on the LAST saturday of the month A 'decent into madness' http://arstechnica.com/civis/viewtopic.php?f=16&t=34360 First attempts all fail... # july would run twice in 2010 1 0 24-31 * 6 /some/script.sh # april would not run at all in 2010 1 0 25-31 * 6 /some/script.sh Note that... echo `cal | awk 'NR>2{print $7}'` gets the days of saturdays for this month, all onto one line So getting the day of the last saturday for this month is... Each line compacting the previous line cal | awk '{print $7}' | grep -E '[0-9]' | tail -n 1 cal | awk '$7~/[0-9]/{print $7}' | tail -n 1 cal | awk '$7{l=$7} END{print l}' The recipe for a last saturday test... [ `date +%d` -eq `cal|awk '$7{l=$7}END{print l}'` ] && CMD Alternative using GNU date (depends on version) To see if the day (saturday) plus 7 days is at the start of a month 0 0 * * 6 [ `date +%d -d '7 days'` -le '7' ] && CMD Or see if next Saturday is in a different month... 1 0 * * 6 [ `date +$m` -eq `date +%m -d "next Saturday"` ] && CMD WARNING: some versions of "cal" starts on mondays, rather than sundays use "cal -s" on those systems. ------------------------------------------------------------------------------- These special time specification "nicknames" which replace the 5 initial time and date fields, and are prefixed with the '@' character, are supported, according to rhel5 manpage. @reboot : Run once after reboot. @yearly : Run once a year, ie. "0 0 1 1 *". @annually : Run once a year, ie. "0 0 1 1 *". @monthly : Run once a month, ie. "0 0 1 * *". @weekly : Run once a week, ie. "0 0 * * 0". @daily : Run once a day, ie. "0 0 * * *". @hourly : Run once an hour, ie. "0 * * * *" -------------------------------------------------------------------------------