|
|
thewatertower.org.uk |
![]() |
| thewatertower.org.uk |
Crontab: the first five fields combine to restrict the schedule. Except for when they don't.7.33.00pm GMT Mon 16th Mar 2009
If you complete both the 'day of month' and 'day of week' fields, cron is likely to behave exactly the way you expect it not to. First, a quick overview for reference. Crontab has six fields; the following .. plus the command to execute.
Any of those fields can be replaced with an asterisk, which stands in for all potential values. So, some examples:
So far, so predictable. 'restrictions' are being applied, and the schedule is running less and less frequently. So, lets say we wanted to run foo on the first Monday of every month. We might think that the following additional restriction would prevent the job running any other Monday:
We'd be really, really wrong. Cron will run foo every Monday *and* every day of the month from the 1st to 7th inclusive. "If both [date] fields are restricted (i.e., aren't *), the command will be run when _either_ field matches the current time." One question. Why? It'd be so easy to put two cron tab entries in to effect the same behaviour. But oh no .. rather than making it intuitive and provide the additional functionality that 'AND' instead of 'OR' provides, they did it this way. Not that I'm bitter.
Bookmark this story at:
Published and promoted by Ben Prescott, 14, St James's Square, Bournemouth, BH5 2BX. All rights reserved. The views expressed are solely those of the author, not of the service provider. |