home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / job201.zip / JOBBER2.CMD next >
OS/2 REXX Batch file  |  1994-07-22  |  3KB  |  118 lines

  1. /* JOBBER2.CMD v2.01 (c)Anglopean Limited 1994*/
  2.  
  3. /* State command file purpose */
  4. say 'JOBBER2.CMD v2.01 (c) Anglopean Limited 1994'
  5. say 
  6. say 'Automatic job scheduler for OS/2'
  7. say
  8.  
  9. /* Define Global variables */
  10. '@ECHO OFF'
  11. LogFile = 'C:\JOBBER\JOBBER2.LOG'
  12. today = Date(B)//7
  13.  
  14. say 'Today is 'Today
  15.  
  16. /* Read in config file */
  17. ConfigFile = 'JOBBER2.DAT'
  18. CfgCntr = 0
  19.  
  20. rc = STREAM(ConfigFile, 'C', 'OPEN')
  21. if rc <> 'READY:' then do
  22.    say 'File JOBBER2.DAT does not exist, no jobs defined, program halted.'
  23.    exit
  24. end  /* Do */
  25.  
  26. Do While lines(ConfigFile)
  27.   rc = LineIn(ConfigFile)
  28.   rc = Strip(rc, 'b', ' ')
  29.   If Left(rc, 1) <> ';' & Length(rc) <> 0 then do
  30.     Parse Value rc with CmdFile ',' Time ',' Flag ',' ExecuteDays
  31.     If ExecuteDays = '' then
  32.       ExecuteDays = '0123456'
  33.     CfgCntr = CfgCntr +1
  34.     action.CfgCntr = CmdFile
  35.     Parse Value Time with ath.cfgcntr ':' atm.cfgcntr
  36.     disk.cfgcntr = Flag
  37.     days.cfgcntr = ExecuteDays
  38.     done.cfgcntr = 0
  39.   End /* If */
  40. End /* Do */
  41.  
  42. rc = stream(ConfigFile, 'C', 'CLOSE')
  43.  
  44. /* Display Config File Contents */
  45. say 'JOBBER2.DAT config file dump'
  46. say
  47. Do Cntr = 1 to CfgCntr
  48.   say action.cntr 'at' ath.cntr':'atm.cntr 'or when' disk.cntr 'exists (on days 'days.cntr')'
  49. end
  50.  
  51. /* Tidy up the screen */
  52. say
  53. say 'Starting main JOBBER process'
  54. say
  55.  
  56. StopFlag = 0
  57.  
  58. /* Define TEMPTIME */
  59. Parse Value Time() with h':'m':'s
  60. TempTime = m
  61.  
  62. /* Main Procdedure */
  63. Do While StopFlag = 0
  64.  
  65.   /* Pause until the minute changes */
  66.   Do While m = TempTime
  67.     Parse Value Time() with h':'m':'s
  68.   End
  69.  
  70.   TempTime = m
  71.  
  72.   If h = 0 & m = 0 then do
  73.     do cntr = 1 to cfgcntr
  74.       done.cntr = 0
  75.     end /* Do */
  76.     today = Date(B)//7
  77.   end /* If */
  78.  
  79.   say Date() Left(Time(), 5) 'checking for jobs to execute'  
  80.  
  81.   If Exist('C:\JOBBER\STOP.FLG') = 1 then StopFlag = 1
  82.  
  83.   Do cntr = 1 to CfgCntr
  84.     If pos(today, days.cntr) <> 0 & ath.cntr = h & atm.cntr = m & done.cntr = 0 then do 
  85.       rc = LineOut(LogFile, Date() Left(Time(), 5) 'starting task' action.cntr 'due to time criteria')
  86.       rc = stream(LogFile, 'C', 'CLOSE')
  87.       say Date() Left(Time(), 5) 'starting task' action.cntr 'due to time criteria'
  88.       start action.cntr
  89.       done.cntr = 1
  90.     End /* If */
  91.   End /* Do */
  92.  
  93.   Do cntr = 1 to CfgCntr
  94.     If exist(disk.cntr) then do 
  95.       rc = LineOut(LogFile, Date() Left(Time(), 5) 'starting task' action.cntr 'due to flag file')
  96.       rc = stream(LogFile, 'C', 'CLOSE')
  97.       say Date() Left(Time(), 5) 'starting task' action.cntr 'due to flag file'
  98.       start action.cntr
  99.     End /* If */
  100.   End /* Do */
  101.  
  102.   Do cntr = 1 to CfgCntr
  103.     If exist(disk.cntr) then do 
  104.       'del' disk.cntr
  105.     End /* If */
  106.   End /* Do */
  107.  
  108. End /* Do While */
  109.  
  110. Exit /* To command line */
  111.  
  112. exist: /* sub-procedure to check if a file exists. retcode = 1 (exists) = 0 (not-exist) */
  113.   arg filename
  114.   rc = Stream(Filename, 'C', 'QUERY EXISTS')
  115.   If rc = '' then RetCode = 0 
  116.     else Retcode = 1  
  117. Return(RetCode)
  118.