home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / daily.zip / DAILY.CMD
OS/2 REXX Batch file  |  1993-10-16  |  3KB  |  90 lines

  1. /* */
  2. /*
  3. This file = Daily.cmd
  4. Author = Alan Thorogood
  5. Date = 7 October 93
  6. Version = 1.0
  7.  
  8. Dedication:
  9.     This REXX procedure is public domain and may be freely distributed, copied and modified.
  10.     Please do not delete the author name.  I may be contacted on Compuserve:100014,3633.
  11.  
  12. Objective:
  13.     Waits until a specified time each day and then executes a command.
  14.     The user presses control-break to stop the cycle.
  15.     The time and command are coded into the Init routine below.
  16.     There are near-zero CPU cycles wasted in serving the Wait routine.
  17.  
  18.     The command may be any valid program name (DOS, OS/2, Windows),
  19.         .cmd, .bat etc. etc..  
  20.     Anything OS/2 can run from its prompt will be executed.
  21.  
  22.     This .cmd file will wait until the called program completes before re-scheduling the
  23.     next run.  This means that if an error occurs and the called program waits for keyboard 
  24.     input then another, similar, process will not start in 24 hours time.
  25.  
  26.     BEWARE!!!
  27.     
  28.     IF this utility is being used to run, say, a tape backup and the tape backup utility terminates 
  29.     on completion AND it is being run over a weekend without attention THEN on Sunday it 
  30.     will re-run the same backup with the Saturday tape still loaded in the drive.
  31.  
  32.     To stop this happening you will need to write a REXX or DOS or Windows or PM procedure 
  33.     that will wait for keyboard input on a Saturday or in all cases.
  34.  
  35. */
  36.  
  37. Main:
  38.     Call Init
  39.     DO WHILE 1
  40.         Call Process
  41.     END
  42.     /* No close routine because the user Control-breaks */
  43.     
  44. Init:
  45.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  46.     call SysLoadFuncs
  47.     
  48. /*************************************************************************
  49.     PUT YOUR TIME AND COMMAND BELOW HERE
  50. **************************************************************************/
  51.  
  52.     JobTime = '09:03:00'            /* Code this with the start time in 24hr format */
  53.     Command = 'HELLO'            /* Code this with the command to execute */
  54.  
  55.     JobHH = LEFT(JobTime,2)
  56.     JobMM = SUBSTR(JobTime,4,2)
  57.     JobSS = RIGHT(JobTime,2)
  58.     JobSeconds = (JobHH * 60 * 60) + (JobMM * 60) + JobSS
  59.  
  60.     Count = 0                /* used for information only on how many times
  61.                             it has been executed */
  62.  
  63.     /* Add the constant MidnightSeconds */
  64.     MidnightSeconds = 24 * 60 * 60
  65.  
  66.     return
  67.  
  68. Process:
  69.     /* get the current time in hh:mm:ss */
  70.     CurrentTime = TIME()
  71.     CurrentHH = LEFT(CurrentTime,2)
  72.     CurrentMM = SUBSTR(CurrentTime,4,2)
  73.     CurrentSS = RIGHT(CurrentTime,2)
  74.     CurrentSeconds = (CurrentHH * 60 * 60) + (CurrentMM * 60) + CurrentSS
  75.  
  76.     /* Calculate seconds to wait allowing for roll around the clock */
  77.     if JobSeconds > CurrentSeconds then    WaitSeconds = JobSeconds - CurrentSeconds
  78.     else WaitSeconds = (MidnightSeconds - CurrentSeconds) + JobSeconds
  79.     if WaitSeconds = 0 then WaitSeconds = MidnightSeconds
  80.  
  81.     say 'This daily wait routine written by Alan Thorogood Cserve ID:100014,3633'
  82.     say 'Since this procedure started it has executed' Count 'times'
  83.     say 'This time it started waiting at' CurrentTime 'and is waiting for' JobTime 
  84.     say 'to execute command:' Command
  85.     call SysSleep WaitSeconds
  86.     'CMD /C ' Command
  87.     Count = Count + 1
  88.     return
  89.  
  90.