home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / crontab.zip / cron.cmd < prev    next >
OS/2 REXX Batch file  |  1998-01-22  |  4KB  |  113 lines

  1. /************************************************************************/
  2. /* cron.cmd                                                          */
  3. /* Created: 18 Jan 1998                                                 */
  4. /* Author: J. Pedone                                                    */
  5. /* jpedone@flash.net                                                    */
  6. /************************************************************************/
  7. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  8. Call sysloadfuncs
  9.  
  10. Signal on Halt
  11. tab='09'x
  12. cr = '0d'x
  13. lf = '0a'x
  14.  
  15. /* Get present working directory */
  16.     workdir = Directory()
  17.     cworkdir = workdir
  18.     fworkdir = workdir||'\'
  19.  
  20. /* get time info */
  21.     currMin = time('m')-time('h')*60
  22.     disp_min = currMin
  23.     if disp_min < 10 then disp_min = '0'disp_min
  24.     currHour = time('h')
  25.     today = date('s')
  26.     currYear = substr(today,1,4)
  27.     currMonth = substr(today,5,2)
  28.     CurrDay = substr(today,7,2)
  29.     today = date('w')
  30.     say 'Cron started at 'currHour':'disp_min' on 'currMonth'/'currDay'/'currYear
  31.  
  32. do forever
  33. /* determine current time and date */
  34.     currMin = time('m')-time('h')*60
  35.     currHour = time('h')
  36.     today = date('s')
  37.     currYear = substr(today,1,4)
  38.     currMonth = substr(today,5,2)
  39.     CurrDay = substr(today,7,2)
  40.     today = date('w')
  41.     disp_min = currMin
  42.     if disp_min < 10 then disp_min = '0'disp_min
  43.     currDow = wordPos(today,'Sunday Monday Tuesday Wednesday Thursday Friday Saturday')
  44.  
  45. /* Parse and check the crontab file */
  46.     do while rc <> 'READY:'
  47.         rc=Stream(fworkdir'crontab','C','Open')
  48.         call SysSleep 1
  49.     End
  50.     do while lines(fworkdir'crontab') > 0
  51.         line = linein(fworkdir'crontab')
  52.         parse var line minutes'≡'hours'≡'days'≡'months'≡'dows'≡'years'≡'session'≡'type'≡'file'≡'parameters'≡'pworkdir'≡'close
  53.         isMin   = matches(minutes, currMin)
  54.         isHour  = matches(hours, currHour)
  55.         isDay   = matches(days,currDay)
  56.         isMonth = matches(months,currMonth)
  57.         isDow   = matches(dows,currDow)
  58.         isYear = matches(years,curryear)
  59.  
  60. /* check the time and launch if it's time */
  61.         if isMin & isHour & isDay & isMonth & isDow & isYear then do
  62.             if type = 'Message' Then Do
  63.                 say 'Launching message at 'currHour':'disp_min' on 'currMonth'/'currDay'/'currYear
  64.                 '@detach 'fworkdir'\DRREXX.EXE 'fworkdir'\msgbox.RES 'file'≡'parameters
  65.             End
  66.             Else Do
  67.                 If session <> 'Detached' Then Do
  68.                     start_string = '@Start'
  69.                     If close = 'Yes' Then start_string = start_string' /c'
  70.                     if session = 'Minimized' then start_string = start_string' /min'
  71.                     if session = 'Full Screen' then start_string = start_string' /fs'
  72.                     if session = 'Window' then start_string = start_string' /win'
  73.                 End
  74.                 If session = 'Detached' Then Do
  75.                     start_string = 'Detach'
  76.                 End
  77.                 wd = strip(pworkdir,'B')
  78.                 if lastpos('\',wd) = length(wd) then do
  79.                     plen = length(wd)-1
  80.                     if plen > 1 Then Do
  81.                         wd = substr(wd,1,plen)
  82.                     End
  83.                 End
  84.                 rc = directory(wd)
  85.                 start_string||' '||strip(file,'B')||' '||strip(parameters,'B')
  86.                  call SysSleep 2
  87.                 rc = directory(cworkdir)
  88.                 say 'launching '||start_string||' '||strip(file,'B')||' '||strip(parameters,'B')||' at '||currHour||':'||disp_min||' on '||currMonth||'/'||currDay||'/'||currYear
  89.             End     /* Else */
  90.         End     /* if time */
  91.     End     /* While */
  92.     call stream fworkdir'crontab','c','close' 
  93.     call sysSleep 60-(time('s')-time('m')*60)
  94.  
  95. End  /* main loop */
  96.  
  97. matches:
  98.     args = arg(1)
  99.     if args='*' then return 1
  100.     matched = 0
  101.     parse var args value ',' args
  102.     do while value<>''
  103.         if value=arg(2) then matched = 1
  104.         parse var value from '-' to
  105.         if from<=arg(2) & arg(2)<=to then matched = 1
  106.         parse var args value ',' args
  107.     end
  108. return matched
  109.  
  110. halt:
  111.     say 'Cron stopped at 'currHour':'disp_min' on 'currMonth'/'currDay'/'currYear
  112. /* end of file */
  113.