Wednesday, February 2, 2011

5) To run on last sunday of a month

If you want a job to run on the last sunday of every month, you can use the following syntax from within cron:

00 18 * * 0 [`date "+%d"` -gt 24] && /path/to/script

i.e. on sundays at 18:00 check if the day of the month is greater than 24 - if so run the job (if 23 is specified the job will run on the last 2 sundays of the month)

NOTE: There are back-ticks "`" around the date command, not single quotes.

No comments:

Post a Comment