Cron - First Saturday of the month
Maarten Litmaath
maart at cs.vu.nl
Sat Aug 11 03:26:39 AEST 1990
The manual (man 5 crontab on SunOS 4.0.3c):
[...]
Note: the specification of days may be made by two fields
(day of the month and day of the week). If both are speci-
fied as a list of elements, both are adhered to. For exam-
ple,
0 0 1,15 * 1
would run a command on the first and fifteenth of each
month, as well as on every Monday. To specify days by only
one field, the other field should be set to *. For example,
0 0 * * 1
would run a command only on Mondays.
[...]
The code:
int
match(cp, loct)
register char **cp;
register struct tm *loct;
{
int cancel_ex = 0;
*cp = cmp(*cp, loct->tm_min, &cancel_ex);
*cp = cmp(*cp, loct->tm_hour, &cancel_ex);
*cp = cmp(*cp, loct->tm_mday, &cancel_ex);
*cp = cmp(*cp, loct->tm_mon, &cancel_ex);
*cp = cmp(*cp, loct->tm_wday, &cancel_ex);
return(!cancel_ex);
}
char *
cmp(p, v, cancel_ex)
char *p;
int *cancel_ex;
{
register char *cp;
cp = p;
switch(*cp++) {
case EXACT:
if (*cp++ != v)
(*cancel_ex)++;
return(cp);
case ANY:
return(cp);
case LIST:
while(*cp != LIST)
if(*cp++ == v) {
while(*cp++ != LIST)
;
return(cp);
}
(*cancel_ex)++;
return(cp+1);
case RANGE:
if(cp[0] < cp[1]) {
if(!(cp[0]<=v && cp[1]>=v))
(*cancel_ex)++;
} else if(!(v>=cp[0] || v<=cp[1]))
(*cancel_ex)++;
return(cp+2);
}
if(cp[-1] != v)
(*cancel_ex)++;
return(cp);
}
The conclusion: the manual and the code contradict each other!
The example
0 0 1,15 * 1
...will run the job on each monday whose date is either the 1st or the 15th!
It might be too late to fix the manual... (Grrrr!)
--
"UNIX was never designed to keep people from doing stupid things, because
that policy would also keep them from doing clever things." (Doug Gwyn)
More information about the Comp.unix.wizards
mailing list