curt@oce.orst.edu (Curt Vandetta) (08/09/90)
Hello folks, I'm wondering if anyone has a way of making cron run a job on the first Saturday of every month? Thanks, Curt -------------------------------------------------------------------------- Curt Vandetta College of Oceanography curt@oce.orst.edu Oregon State University
merlyn@iwarp.intel.com (Randal Schwartz) (08/09/90)
In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes: | I'm wondering if anyone has a way of making cron run a job on the | first Saturday of every month? 3 4 1-7 * 6 command to make 'command' run at 4:03am... adjust the first two fields as necessary. Remember, the parameters are "and"-ed together. #ifdef FLAME_ABOUT_INAPPROPRIATE_GROUP This is not a wizard question. Wizards generally know cron things, especially things that can be found with "man 5 crontab". Do not post to wizards unless you *are* a wizard, and if you have any doubt about whether you are a wizard or not, you're not! Now, if you had asked which versions of cron did *not* provide /etc in the PATH... that'd be a wizard question. :-) #endif Just another UNIX hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
dmcanzi@watserv1.waterloo.edu (David Canzi) (08/09/90)
In article <1990Aug8.185745.16606@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes: >| I'm wondering if anyone has a way of making cron run a job on the >| first Saturday of every month? > >3 4 1-7 * 6 command > >to make 'command' run at 4:03am... adjust the first two fields as >necessary. Remember, the parameters are "and"-ed together. > >#ifdef FLAME_ABOUT_INAPPROPRIATE_GROUP > >This is not a wizard question. Wizards generally know cron things, >especially things that can be found with "man 5 crontab". Do not post >to wizards unless you *are* a wizard, and if you have any doubt about >whether you are a wizard or not, you're not! > >Now, if you had asked which versions of cron did *not* provide /etc in >the PATH... that'd be a wizard question. :-) Apparently, there is at least one version of cron which has somehow escaped your wizardly notice. Here is what "man 5 crontab" says at my site: 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. Now, given a version of cron that behaves this way, one would have to settle for a crontab entry that runs one's program every Saturday, and have the program itself check to see whether it's the first week of the month. In a csh script, this can be accomplished by: set dt= ( `date` ) if ( $dt[3] <= 7 ) then ... endif In a sh script, it can be done by: if [ `date | sed 's/^... ... *\([^ ]*\) .*/\1/'` -le 7 ]; then ... fi -- David Canzi
merlyn@iwarp.intel.com (Randal Schwartz) (08/09/90)
In article <1990Aug8.214539.1264@watserv1.waterloo.edu>, dmcanzi@watserv1 (David Canzi) writes: | Apparently, there is at least one version of cron which has somehow | escaped your wizardly notice. Here is what "man 5 crontab" says at | my site: | | 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. | Interesting, but after finishing reading the manpage (I have that very same manpage on sunos4.1), I notice that it contradicts itself a little later in saying that " 0 0 * * 1 " " would run a command only on Mondays. Now wait a second, since "*" says "any match'll do", this command would run *every* day, not on Mondays, using the "or" logic described earlier in the previous paragraph. I submit that the writers of that there manpage just didn't know what they were talking about. As a real guru hacking the One True Unix, I would then curse the manpage author, and go look at the source. However, since I haven't seen UNIX source (UNIX without source... a mortal sin) for 5 years (gack!!!), I cannot resolve this by myself. Help, someone? Does it really use "or" logic or something even more strangely convoluted? Or is it "and" logic, like it was back in V7 (the One True Unix... system V isn't even close). Yeah, OK, so I'm a bit religious. (SunOS isn't UNIX either, but at least it is upward compatible with V7. :-) Just another old-time UNIX hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
jackal@munsell.UUCP (Phil Hammar) (08/09/90)
In article <1990Aug8.185745.16606@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes: >| I'm wondering if anyone has a way of making cron run a job on the >| first Saturday of every month? > >3 4 1-7 * 6 command > >to make 'command' run at 4:03am... adjust the first two fields as >necessary. Remember, the parameters are "and"-ed together. > From the SunOS 4.1 crontab(5) manual page (Quoted without permission): 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. From this excerpt (and experience), the day fields are OR'd. If anyone know the real way to do this for SunOS 4.X, I'd appreciate the answer too. Follow-ups to comp.unix.questions. G'day, Phil Hammar -- Philip Hammar Sys. Admin. for AES of EPPS, a wholly owned subsidiary of E. KODAK Co. ...!{harvard!ima,uunet!atexnet}!munsell!jackal ph:(617)276-7249
rls@svcs1.UUCP (Bob Strait) (08/10/90)
In article <19744@orstcs.CS.ORST.EDU> curt@oce.orst.edu (Curt Vandetta) writes: > I'm wondering if anyone has a way of making cron run a job on the > first Saturday of every month? > How about running your job each of the first seven days of every month, and have the job first test whether it's Saturday and exit if it's not. There are several easy ways to do the test: 'date | grep Sat' comes to mind. -- BUBBA (aka Bob Strait) ...!mips!svcs1!rls Silicon Valley Computer Society Sunnyvale, CA --
guy@auspex.auspex.com (Guy Harris) (08/10/90)
>Or is it "and" logic, like it was back in V7 (the One True Unix... >system V isn't even close). > >Yeah, OK, so I'm a bit religious. (SunOS isn't UNIX either, but at >least it is upward compatible with V7. :-) Hate to bust yer balloon, but "cron" in SunOS 4.x is based on the System V Release 3.1 "cron" (and its man page is based on the S5R3.1 man page)....
bob@wyse.wyse.com (Bob McGowen x4312 dept208) (08/10/90)
In article <1990Aug8.185745.16606@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes: >| I'm wondering if anyone has a way of making cron run a job on the >| first Saturday of every month? > >3 4 1-7 * 6 command > >to make 'command' run at 4:03am... adjust the first two fields as >necessary. Remember, the parameters are "and"-ed together. ...flame deleted My documentation states that a line like the one you have provided would cause the command to run on EVERY Saturday as well as on each of the first seven days in the month. My flame-- I would be very interested if you could provide a cron only method of getting my cron to execute on the first Saturday (or any other day) such that it executes on that single day only. My attempts at solving this have been to combine cron to run the command on Saturday and have command be a script that checks the date to be sure it is less than or equal to 7. But this only works for the first 13 days so I have to figure out the next exclusion, probably to limit between a start and stop. In any case, getting cron to do what Curt wants is a little more difficult. Possibly (probably, I think) even wizard caliber. Bob McGowan (standard disclaimer, these are my own ...) Product Support, Wyse Technology, San Jose, CA ..!uunet!wyse!bob bob@wyse.com
dmcanzi@watserv1.waterloo.edu (David Canzi) (08/10/90)
In article <1990Aug9.001850.19494@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >I submit that the writers of that there manpage just didn't know what >they were talking about. As a real guru hacking the One True Unix, I >would then curse the manpage author, and go look at the source. >However, since I haven't seen UNIX source (UNIX without source... a >mortal sin) for 5 years (gack!!!), I cannot resolve this by myself. >Help, someone? In the absence of source code, you experiment. At 23:32 on Thursday, Aug 9, these were the contents of my crontab: 32 23 1-5 * 1 date > /u/dmcanzi/temp/www 32 23 7-11 * 4 date > /u/dmcanzi/temp/xxx 32 23 1-5 * 4 date > /u/dmcanzi/temp/yyy 32 23 7-11 * 1 date > /u/dmcanzi/temp/zzz The files xxx, yyy, and zzz were created, www was not created. The manual page is correct. -- David Canzi
merlyn@iwarp.intel.com (Randal Schwartz) (08/10/90)
In article <1990Aug10.040654.17334@watserv1.waterloo.edu>, dmcanzi@watserv1 (David Canzi) writes: | In the absence of source code, you experiment. At 23:32 on Thursday, | Aug 9, these were the contents of my crontab: | | 32 23 1-5 * 1 date > /u/dmcanzi/temp/www | 32 23 7-11 * 4 date > /u/dmcanzi/temp/xxx | 32 23 1-5 * 4 date > /u/dmcanzi/temp/yyy | 32 23 7-11 * 1 date > /u/dmcanzi/temp/zzz | | The files xxx, yyy, and zzz were created, www was not created. The | manual page is correct. See, but now that makes cron non-orthogonal. Yuck. So, without looking at the source, I have to second-guess the logic. Is it: minutes-match AND hours-match AND (days-match OR dow-match) AND months-match (meaning 0 0 1 7 1 would run on the first of June and all Mondays in June) or: minutes-match AND hours-match AND ((days-match AND months-match) OR dow-match) (meaning 0 0 1 7 1 would run on the first of June and all Mondays in any month) or: some-other-combination-that-I-didn't-type-in Either way, throwing that OR in there means the manpage is incomplete. (And cron is hard to inuitively guess now.) Putting it another way, I could not work from the manpage and build a cron that is guaranteed to work the same way as out-of-the-box cron. Don't have a POSIX spec in front of me. What do they say about this ambiguity? By the way, cron logic like this is backwards. You can always get OR logic by duplicating the entries. To get AND logic, you have to have something *in* the command make an additional decision. And, continuing on with my tirade, since it says earlier in the manpage "if a field is an asterisk character (*) it means that the job is done for all possible values of the field", that would make me believe that: 0 0 * * 1 would work the same as: 0 0 1-31 * 1 which is not true. (The first executes 4 times a month, the second 31 times a month [more or less]). This (now incorrect) intuition follows from noticing that: * 0 * * * is the same as: 0-59 0 * * * So, they really mucked up when they OR-ed in that day-of-week field. Sigh. Sorry. I'll crawl under my rock now. Cron's only for the heavyweights, anyway. Just another UNIX hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
p554mve@mpirbn.mpifr-bonn.mpg.de (Michael van Elst) (08/10/90)
In article <1990Aug8.185745.16606@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: >In article <19744@orstcs.CS.ORST.EDU>, curt@oce (Curt Vandetta) writes: >| I'm wondering if anyone has a way of making cron run a job on the >| first Saturday of every month? >3 4 1-7 * 6 command >to make 'command' run at 4:03am... adjust the first two fields as >necessary. Remember, the parameters are "and"-ed together. From the SunOS4.03 Manual: Note: the specification of days may be made by two fields (day of the month and day of the week). If both are specified as a list of elements, both are adhered to. For example: 0 0 1,15 * 1 command would run a command on the first and the fifteenth of each month, as well as on every Monday. . . Seems that, at least here, your suggestion doesn't work. -- Michael van Elst UUCP: universe!local-cluster!milky-way!sol!earth!uunet!unido!mpirbn!p554mve Internet: p554mve@mpirbn.mpifr-bonn.mpg.de "A potential Snark may lurk in every tree."
anselmo-ed@cs.yale.edu (Ed Anselmo) (08/10/90)
I peeked at the sources -- the BSD cron "ands" all the fields together. I don't have Sun 4.x sources, but under SunOS 4.0.3, I saw the same behavior as David Canzi saw. So, with a crontab like: 28 12 1-5 * 5 anselmo date > /homes/facility/anselmo/temp/www 28 12 7-11 * 1 anselmo date > /homes/facility/anselmo/temp/xxx 28 12 1-5 * 1 anselmo date > /homes/facility/anselmo/temp/yyy 28 12 7-11 * 5 anselmo date > /homes/facility/anselmo/temp/zzz running on Fri Aug 10, under the BSD cron, only zzz got created. Running under Sun 4.x cron (with the crontab entries suitably modified), www, xxx, and zzz got created. -- Ed Anselmo anselmo-ed@cs.yale.edu {harvard,cmcl2}!yale!anselmo-ed
maart@cs.vu.nl (Maarten Litmaath) (08/11/90)
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)
chip@tct.uucp (Chip Salzenberg) (08/11/90)
According to dmcanzi@watserv1.waterloo.edu (David Canzi):
>if [ `date | sed 's/^... ... *\([^ ]*\) .*/\1/'` -le 7 ]
At least on SysV, this is working too hard! Use this instead:
if [ "`date +%d`" -le 7 ]
Manual pages are wonderful things...
--
Chip Salzenberg at ComDev/TCT <chip@tct.uucp>, <uunet!ateng!tct!chip>
maart@cs.vu.nl (Maarten Litmaath) (08/11/90)
In article <7286@star.cs.vu.nl>, I wrote:
)The manual (man 5 crontab on SunOS 4.0.3c):
)...
)The code:
)...
I forgot to mention the code is _not_ SunOS 4.0.3c (still no up to date
sources...)
Anyway, my point still stands: _anding_ the fields is preferred (as Randal
already explained), but it might be too late to fix the specifications...
--
"UNIX was never designed to keep people from doing stupid things, because
that policy would also keep them from doing clever things." (Doug Gwyn)
ronald@robobar.co.uk (Ronald S H Khoo) (08/11/90)
In article <1990Aug10.063819.5253@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: > Sigh. Sorry. I'll crawl under my rock now. Cron's only for the > heavyweights, anyway. System V cron isn't just for heavyweights, though, it's got per-user crontabs, remember, so joe-random-non-wizard who has his own crontab has to understand the manpage. Sigh. Someone once mentioned wanting to write a System V-like cron in perl so he could have per-user crontabs on his machine. I wonder who it was, and how he parsed the manpage ? -- Eunet: Ronald.Khoo@robobar.Co.Uk Phone: +44 81 991 1142 Fax: +44 81 998 8343 Paper: Robobar Ltd. 22 Wadsworth Road, Perivale, Middx., UB6 7JD ENGLAND.
kpc00@JUTS.ccc.amdahl.com (kpc) (08/11/90)
In article <1990Aug10.063819.5253@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes: So, they really mucked up when they OR-ed in that day-of-week field. Sigh. Sorry. I'll crawl under my rock now. Cron's only for the heavyweights, anyway. Because it's job security through obscurity :-)? Your posting was good. One might hope that HLL boolean expressions were at least considered in the design of cron. (I hope that this offends nobody. In particular, I hope that the designer of cron is not reading this or is not offended -- it really is a wonderful tool, but why was APL-minus-minus chosen as the time description language? :-)) For UNIX historians: Was an HLL expression syntax ever considered? (Or was the original machine thought to be too slow for it?) Also, now that the OR is in there, which of merlyn's possibilities was correct? It makes one wonder what things, if any, are not possible in cron without putting something in the command to be executed. -- Neither representing any company nor, necessarily, myself.
merlyn@iwarp.intel.com (Randal Schwartz) (08/11/90)
In article <7286@star.cs.vu.nl>, maart@cs (Maarten Litmaath) writes: | The code: [deleted to protect my eyes, but it *is* the code I remember ...] | 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!) Yes, this is my point. Actually, what I think happened is that you posted the V7-derived cron, and Sunos4.1 went to the user-crontab System (blech) V cron, and I suspect that they put some widgets in there to do this stupid "OR" logic that I complained about in my last two postings. Anyone with access to system V source care to comment? Are there some yucky kludges in there? Just another System V disliker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
dmcanzi@watserv1.waterloo.edu (David Canzi) (08/11/90)
In article <1990Aug8.214539.1264@watserv1.waterloo.edu> I wrote: >In a sh script, it can be done by: > >if [ `date | sed 's/^... ... *\([^ ]*\) .*/\1/'` -le 7 ]; then > ... >fi This is better done using awk: if [ `date | awk '{print $3}'` -le 7 ]; then ... fi -- David Canzi
merlyn@iwarp.intel.com (Randal Schwartz) (08/12/90)
In article <KPC00.90Aug10144909@JUTS.ccc.amdahl.com>, kpc00@JUTS (kpc) writes: | Also, now that the OR is in there, which of merlyn's possibilities was | correct? It makes one wonder what things, if any, are not possible in | cron without putting something in the command to be executed. Well, we already have one. The original request! (See Subject: :-) Sigh. -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
alter@ttidca.TTI.COM (Steve Alter) (08/15/90)
In article <19744@orstcs.CS.ORST.EDU> curt@oce.orst.edu (Curt Vandetta) writes: } I'm wondering if anyone has a way of making cron run a job on the } first Saturday of every month? I'm going to totally side-step the fight that has been waged over whether the day-of-week is logically ANDed or ORed with the day-of-month. You can set it up using a combination of cron and "at". For example, let's assume that you want the job to run at 1 a.m. on the first Saturday of each month. You put in a cron job to run at 12:30 a.m. on the 1st DAY of each month, and have that cron job launch an "at" job to run at 1 a.m. on the next Saturday, which could be as soon as 30 minutes later. Tweak the names and numbers to your heart's delight, but the concept remains. The cron line (SunOS 4.x): 30 0 1 * * /home/myacct/bin/next.Saturday The next.Saturday script (mode 755): at -c 0100 Sat first.Saturday.of.month File "first.Saturday.of.month" contains... oh, you can figure it out. -- Steve Alter <alter@ttidca.tti.com> {csun,philabs,psivax,pyramid,quad1,rdlvax,retix}!ttidca!alter Citicorp/TTI, Santa Monica CA (213) 450-9111 x2541
bj@dc.luth.se (B|rje Josefsson) (08/16/90)
Slightly a side question according to the Subject:, but how to setup a command for execution on the LAST day of the month ONLY? I could use: 0 0 31 1 * command 0 0 28 2 * command 0 0 31 3 * command and so on but that will not work on leap years... --Borje ----------------------------------------------------------------------------- Borje Josefsson, Computer centre, University of Lulea, S-951 87 Lulea, Sweden Tel: +46 920 91 262 (direct), +46 920 91 000 (operator). Fax: +46 920 972 88 Domain: bj@dc.luth.se Path: {uunet,mcsun,sunic}!dc.luth.se!bj
volpe@underdog.crd.ge.com (Christopher R Volpe) (08/16/90)
In article <1489@hagbard.dc.luth.se>, bj@dc.luth.se (B|rje Josefsson) writes: |>Slightly a side question according to the Subject:, but how to setup a |>command for execution on the LAST day of the month ONLY? |> |>I could use: |> 0 0 31 1 * command |> 0 0 28 2 * command |> 0 0 31 3 * command |> and so on |>but that will not work on leap years... |> |>--Borje Set the date on your machine to one day ahead of the real date, and tell cron to run your application on the first of each month. ( 1/2 :-) ) ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (08/16/90)
In article <1489@hagbard.dc.luth.se> bj@dc.luth.se (B|rje Josefsson) writes:
: Slightly a side question according to the Subject:, but how to setup a
: command for execution on the LAST day of the month ONLY?
:
: I could use:
: 0 0 31 1 * command
: 0 0 28 2 * command
: 0 0 31 3 * command
: and so on
: but that will not work on leap years...
I'd suggest (surprise, surprise)
0 0 * * * perl -e '(localtime(time + 24*60*60))[3] == 1 && exec "command"'
or, more concisely
0 0 * * * perl -e 'exit+(localtime time+86400)[3]-1' && command
Larry Wall
lwall@jpl-devvax.jpl.nasa.gov
dmcanzi@watserv1.waterloo.edu (David Canzi) (08/16/90)
In article <3706@aspect.UUCP> dave@aspect.UUCP (Dave Corcoran) writes: >In article <1990Aug11.030818.28876@watserv1.waterloo.edu>, dmcanzi@watserv1.waterloo.edu (David Canzi) writes: >> if [ `date | awk '{print $3}'` -le 7 ]; then > >or: >if [ `date +%d` -le 7 ] This doesn't work on all the machines I have access to, so I prefer the solution using awk. -- David Canzi
tkevans@fallst.UUCP (Tim Evans) (08/18/90)
In <19137@ttidca.TTI.COM> alter@ttidca.TTI.COM (Steve Alter) writes: >In article <19744@orstcs.CS.ORST.EDU> curt@oce.orst.edu (Curt Vandetta) writes: >} I'm wondering if anyone has a way of making cron run a job on the >} first Saturday of every month? >I'm going to totally side-step the fight that has been waged over >whether the day-of-week is logically ANDed or ORed with the day-of-month. >You can set it up using a combination of cron and "at". You can also let the job itself figure out what day it is and decide whether to run. The following fragment is from a script which is run _every_ Wednesday on my system; depending on the day of the month, it does different things. (Specifically, on the 2nd Wednesday of the month, it does one thing, on the 3rd Wednesday, it does something else, and on all other Wednesdays, it does nothing.) # extract 3rd field of output from date command set `date` TODAY=$3 case "$TODAY" in 8|9|10|11|12|13|14) # it's the 2nd Wednesday; send reminder echo "FOO DISTRIBUTION NEXT WEEK ------------------------------ This is to remind you that the regular monthly distribution of foo will take place next Wednesday. If you have any corrections/updates, please send your updates no later than close of business Friday. If you have any questions, please contact so-and-so" | mail aliaslist;; # it's the 3rd Wednesday; do it! 15|16|17|18|19|20|21) DistMachDb;; # call shell function to do distribution # it's any Wednesday other than 2nd or 3rd, so just quit *) exit 0;; esac -- UUCP: {rutgers|ames|uunet}!mimsy!woodb!fallst!tkevans INTERNET: tkevans%fallst@wb3ffv.ampr.org Tim Evans 2201 Brookhaven Ct, Fallston, MD 21047
cliffs@sun.com (Clifford C. Skolnick) (08/20/90)
In article <1489@hagbard.dc.luth.se> bj@dc.luth.se (B|rje Josefsson) writes:
Slightly a side question according to the Subject:, but how to setup a
command for execution on the LAST day of the month ONLY?
I could use:
0 0 31 1 * command
0 0 28 2 * command
0 0 31 3 * command
and so on
but that will not work on leap years...
Can you change the problem so that the program executes it the first minute of
every month instead? If not, use cron to call a script on the 28 of every
month that will enter an at job for the last day of the month. Writing this
shell script is an excercise for the reader :-)
--
Cliff Skolnick - Technical Consultant cliffs@east.sun.com
[I only work for Sun, I do not speak for them]
"The floggings will continue until morale improves"
Makey@Logicon.COM (Jeff Makey) (08/21/90)
To change the topic only slightly, it's worth pointing out that cron really isn't reliable enough to use for monthly operations: if your system happens to be down at the appointed time cron won't realize that it missed executing something when it finally comes up. Sometimes this is the Right Thing To Do, but usually it isn't. Fortunately, at(1) will make up for missed events if you need that capability. Unfortunately, the command syntax of at(1) doesn't make it any easier to run on the first Saturday of the month. :: Jeff Makey Department of Tautological Pleonasms and Superfluous Redundancies Department Disclaimer: All opinions are strictly those of the author. Internet: Makey@Logicon.COM UUCP: {nosc,ucsd}!logicon.com!Makey