home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 182.lha / ARexxCron / RXCron.rex < prev    next >
OS/2 REXX Batch file  |  1988-04-28  |  3KB  |  81 lines

  1. /* RXCron: a "cron" program for the ARexx (1.06+) environment.   *
  2.  *  Version 0.2  10-10-88    Author: Robert Rethemeyer (@BBS-JC) *
  3.  *  Status: PUBLIC DOMAIN, offered "as-is" (no warranties, etc.) *
  4.  *  Format: "RXCRON [cronfile]" to run the program               *
  5.  *          "RXCRON -k"         to kill it                       *
  6.  */
  7. runprog="runwsh >nil:" /* or RUN or ARUN */
  8. arg cfile
  9. select
  10.  when cfile="?" then do
  11.    say sourceline(4)||sourceline(5); exit; end
  12.  when cfile="-K" then do
  13.    call setclip("rxckill",1)
  14.    say "Be patient... RXCron will terminate within one minute"
  15.    exit; end
  16.  otherwise do
  17.   if cfile="" then cfile="s:crontab"
  18.   if ~exists(cfile) then do; say "RXCron can't find" cfile; exit 20; end
  19.   end
  20. end
  21. call setclip("rxckill","00")
  22.  
  23. DO FOREVER
  24. if getclip("rxckill") then do; say "RXCron terminated." ; exit ; end
  25. parse value statef(cfile) with a b c d e t1 t2  /* if file time stamp has   */
  26. tstamp=t1||t2                                   /* changed, reread the file */
  27. if tstamp~=ostamp then do;
  28.   if ~open(cron,cfile,'R') then exit 21
  29.   do n=1 until eof(cron)
  30.     cline.n = readln(cron)
  31.     if eof(cron) then leave
  32.     cline.n=translate(cline.n," ",'09'x) /* removes tabs */
  33.     parse value cline.n with cmin.n chr.n cday.n cmon.n cwd.n cmd.n
  34.     end
  35.   n=n-1
  36.   call close cron
  37.   say "RXCron found" n "entries in new" cfile
  38.   if n=0 then exit 22
  39.   ostamp=tstamp
  40.   end
  41.  
  42. t=time() ; d=date("U")  /* get current date&time */
  43. hr =substr(t,1,2) ; min=substr(t,4,2) ; mon=substr(d,1,2) ; day=substr(d,4,2)
  44. wd=(index("xSuMoTuWeThFrSa",substr(date("W"),1,2))/2)-1
  45.  
  46. do x=1 to n
  47.   if  cline.x = ""      then iterate x
  48.   if ~match(mon,cmon.x) then iterate x
  49.   if ~match(wd,cwd.x)   then iterate x
  50.   if ~match(day,cday.x) then iterate x
  51.   if ~match(hr,chr.x)   then iterate x
  52.   if ~match(min,cmin.x) then iterate x
  53.   say "RXCron @" mon||"/"||day hr||":"||min "->" cmd.x
  54.   runprog cmd.x
  55.   end
  56. call delay 50*(60-substr(time(),7,2))   /* wait until next minute */
  57. END; exit /* end of main program */
  58.  
  59. /* Match... matches numbers with crontab specifications */
  60. Match: /* PROCEDURE    returns boolean */
  61. arg aa,bb
  62. k=verify("*,-0123456789",bb,"M")
  63. select
  64.   when k=0 then do; say "RXCron detected bad number/expr:" bb; exit 11; end
  65.   when k=1 then return 1  /* splat */
  66.   when k=2 then do       /* comma */
  67.      w=translate(bb," ",",")
  68.      do m=1 to words(w)
  69.        if aa=word(w,m) then return 1
  70.        end
  71.      return 0
  72.      end
  73.   when k=3 then do      /* dash */
  74.      w=translate(bb," ","-")
  75.      p=word(w,1); q=word(w,2)
  76.      if aa>=p & aa<=q then return 1; else return 0
  77.      end
  78.   otherwise if aa=bb then return 1; else return 0
  79. end
  80. exit 23  /* should never get here */
  81.