home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / fcron.zip / FCRON.CMD next >
OS/2 REXX Batch file  |  1995-06-04  |  3KB  |  101 lines

  1. /* Written on May 21 1995 by John J. Moss */
  2.  
  3. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' 
  4. call SysLoadFuncs
  5.  
  6. CronTabFile = 'C:\FCron.Tab'
  7. CronLogFile = 'C:\FCron.Log'
  8. Interval = 30
  9.  
  10. call SysCls
  11. call SysCurState 'OFF'
  12. rc = SysSetIcon('FCron.Cmd', 'dumb.ico')
  13.  
  14. say '+--------------------------+'
  15. say '|   FCron for OS/2         |'
  16. say '|   Ver 1.01 May 21 1995   |'
  17. say '+--------------------------+'
  18. say ''
  19. say 'FCron Table = ' || CronTabFile
  20. say '---------------------------------------------------------'
  21.  
  22. i = 0
  23. do while lines(CronTabFile)
  24.     Buf=linein(CronTabFile)
  25.     if (left(Buf,1) = '#') | (length(Buf) = 0) then iterate 
  26.     i = i + 1
  27.     Rec.i.Minute = '' ; Rec.i.Hour = '' ; Rec.i.MonthDay = ''
  28.     parse var Buf Rec.i.Minute Rec.i.Hour Rec.i.MonthDay Rec.i.Month, 
  29.         Rec.i.WeekDay Rec.i.Command
  30.     Rec.i.Month = translate(Rec.i.Month)     /* convert to upper case */
  31.     Rec.i.WeekDay = translate(Rec.i.WeekDay) /* convert to upper case */
  32.     Rec.i.Executed = 0
  33.     say Rec.i.Minute Rec.i.Hour Rec.i.MonthDay Rec.i.Month Rec.i.WeekDay,
  34.         Rec.i.Command
  35. end
  36.  
  37. do forever
  38.     call CurrentTime             /* get current time */
  39.     /* for every command in the table, check time vars */
  40.     do j=1 to i
  41.         if DoCommandNow(j) = 1 then do
  42.             if Rec.j.Executed = 0 then do
  43.                 say date() time() ':::' Rec.j.Command
  44.                 '@echo' date() time() ':::' Rec.j.Command '>>' CronLogFile
  45.                 '@' || Rec.j.Command
  46.                 Rec.j.Executed = 1
  47.                 Rec.j.LMinute = Now.Minute
  48.                 Rec.j.LHour = Now.Hour
  49.                 Rec.j.LMonthDay = Now.MonthDay
  50.                 Rec.j.LMonth = Now.LMonth
  51.                 Rec.j.LWeekDay = Now.WeekDay
  52.             end
  53.         end
  54.     end
  55.     call SysSleep Interval
  56. end
  57.  
  58. /* This function loads and parses the current time into chunks which can be */
  59. /* used by this program. */
  60.  
  61. CurrentTime:
  62.     Now.Time = time()
  63.     Now.Date = date()
  64.     parse var Now.Time Now.Hour':'Now.Minute':'Now.Second
  65.     parse var Now.Date Now.Month Now.MonthDay Now.Year
  66.     Now.Month = translate(left(Now.Month, 3))
  67.     Now.WeekDay = translate(left(date('W'), 3))
  68. return
  69.  
  70. /* This function is what decides whether it is time to do a command or not. */
  71. /* It makes calls to the Match function to determine whether the current */
  72. /* time matches any of the times in the cron.tab file. */
  73. /* Returns 1 if it is time to execute the command or 0 if not. */
  74.  
  75. DoCommandNow: 
  76.     parse arg ix 
  77.     /* As soon as one argument does not match, kick-out of this routine */
  78.     Answer = 0
  79.     if (Match(ix Rec.ix.Minute Now.Minute Rec.ix.LMinute) = 1 &, 
  80.         Match(ix Rec.ix.Hour Now.Hour Rec.ix.LHour) = 1 &,
  81.         Match(ix Rec.ix.MonthDay Now.MonthDay Rec.ix.LMonthDay) = 1 &,
  82.         Match(ix Rec.ix.Month Now.Month Rec.ix.LMonth) = 1 &,
  83.         Match(ix Rec.ix.WeekDay Now.WeekDay Rec.ix.LWeekDay)) then Answer = 1 
  84.     else
  85.         Rec.Cmd.Executed = 0
  86. return Answer
  87.  
  88. /* This function returns 1 if the arguments supplied indicate that a command */
  89. /* is ripe to be executed or 0 if not.  This is how we ensure that a command */
  90. /* gets executed only once during the designated time instead of executing   */
  91. /* every time the program wakes up during that period.                       */
  92.  
  93. Match: 
  94.     parse arg Cmd Rec Now Last
  95.     RetVal = 0
  96.     if ((Rec = '*') | (Rec = Now) | (pos(Now, Rec) > 0)) then do
  97.         if Rec.Cmd.Executed = 1 then if Last \= Now then RetVal = 1
  98.         if Rec.Cmd.Executed = 0 then RetVal = 1
  99.     end
  100. return RetVal
  101.