home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / sched10.zip / sched.cmd < prev    next >
OS/2 REXX Batch file  |  1995-07-19  |  6KB  |  159 lines

  1. /*****************************************************************************/
  2. /* Sched - An automated program launcher - (C) Raphaël Vanney, 1995          */
  3. /*****************************************************************************/
  4. /* Configuring Sched is a simple matter of adapting the program to suit      */
  5. /* your needs. The part that should be edited is everything before the       */
  6. /* comment that reads "Private initializations".                             */
  7. /*****************************************************************************/
  8.  
  9. /* LogFile defines the name of the file where Sched will put some            */
  10. /* information regarding the events it processed.                            */
  11.  
  12. LogFile="e:\lora\logs\Sched.Log"
  13.  
  14. /* Debug defines whether Sched vill verbosely tell the user what's going     */
  15. /* on. It is advisable to set it to 1 to activate it untill you get a fully  */
  16. /* working setup.                                                            */
  17.  
  18. Debug=0
  19.  
  20. /* EvtCnt defines the number of events to schedule. There's no theoric       */
  21. /* limit to the number of events you may define.                             */
  22.  
  23. EvtCnt=3
  24.  
  25. /* For each event, you must define four variables :                          */
  26. /* EvtTim.x  : the time at which the event should occur                      */
  27. /* EvtDay.x  : days the event should occur. Use "0" for monday, "1" for      */
  28. /*             tuesday, etc...                                               */
  29. /* EvtStr.x  : the complete parameter string that will be passed to the      */
  30. /*             "start" command when the event occurs.                        */
  31. /* EvtDsc.x  : a short description of the event. This description being      */
  32. /*             used to identify the event in the .INI file, it is NOT        */
  33. /*             advisable that several events have the same description.      */
  34.  
  35. EvtTim.1="15:00"
  36. EvtDay.1="0123456"
  37. EvtStr.1="/b /c /Win /Min d:\rva\4os2\4os2.exe /c e:\Lora\Zips.Btm"
  38. EvtDsc.1="Sauvegardes diverses"
  39.  
  40. EvtTim.2="8:00"
  41. EvtDay.2="0123456"
  42. EvtStr.2="/b /c /Win /Min d:\rva\4os2\4os2.exe /c e:\Lora\SqFilt.Btm"
  43. EvtDsc.2="SqFilters"
  44.  
  45. EvtTim.3="18:30"
  46. EvtDay.3="6"
  47. EvtStr.3="/b /c /Win /Min d:\RVa\IBMAV\RVa.Cmd"
  48. EvtDsc.3="IBM Anti-virus"
  49.  
  50. /**************************************************************************/
  51. /*                The user-configuration area ends here !                 */
  52. /**************************************************************************/
  53.  
  54. /**************************************************************************/
  55. /* Private initializations                                                */
  56. /**************************************************************************/
  57.  
  58. Call Log "Sched begin"
  59.  
  60. call RxfuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  61. call SysLoadFuncs
  62.  
  63. Arg Prm
  64. If Prm="DEBUG" Then Debug=1
  65.  
  66. IniFile="Sched.Ini"
  67. LastExec="Scheduled apps last exec"
  68.  
  69. rc=SysFileTree("Sched.Cmd", Res, "FO")
  70. If Res.0=0 Then Do
  71.      Say "Sched MUST be launched from the directory where it resides."
  72.      Exit
  73. End
  74. rc=SysSetIcon("Sched.Cmd", "Sched.Ico")
  75.  
  76. Do i=1 To EvtCnt
  77.      EvtTim.i=MakeTime(EvtTim.i)
  78. End
  79.  
  80. /**************************************************************************/
  81. /* Fetch last execution dates for each event                              */
  82. /**************************************************************************/
  83.  
  84. Say "Checking the ini file..."
  85.  
  86. Do i=1 To EvtCnt
  87.      rc=SysIni(IniFile, LastExec, EvtDsc.i)
  88.      If rc="ERROR:" Then Do
  89.           If Debug Then Say EvtDsc.i" has never been run."
  90.           EvtTdy.i=0
  91.      End
  92.      Else Do
  93.           If Debug Then Say EvtDsc.i" was last executed on "rc
  94.           If rc<Date(Sorted) Then EvtTdy.i=0
  95.                              Else EvtTdy.i=1
  96.      End
  97. End
  98.  
  99. /**************************************************************************/
  100.  
  101. Say "Sched enters its forever loop"
  102. '@echo on'
  103.  
  104. Last=0
  105.  
  106. Do ForEver
  107.      t=Time(Minutes)          /* current time, minutes elapsed since midnight */
  108.      d=Date(BaseDate)//7      /* current day of week, 0..6 */
  109.      If t<Last Then Do
  110.           /* on a changé de jour */
  111.           If Debug Then Say "New Day! ("Date()" at "Time(Normal)")"
  112.           Call Log "New day"
  113.           Do i=1 To EvtCnt
  114.                EvtTdy.i=0
  115.           End
  116.      End
  117.      Last=t
  118.      If Debug Then Say "Time is "t
  119.  
  120.      Do i=1 To EvtCnt
  121.           If Debug Then Say "Event "EvtDsc.i" at "EvtTim.i" (Done today="EvtTdy.i")"
  122.           If EvtTdy.i=0 Then            /* if event not done today */
  123.           If Pos(d, EvtDay.i)<>0 Then   /* if day of week matches */
  124.           If EvtTim.i <= t Then Do      /* if time justifies */
  125.                EvtTdy.i=1
  126.                rc=SysIni(IniFile, LastExec, EvtDsc.i, Date(Sorted))
  127.                Say "Starting event n°"i" ("EvtDsc.i")"
  128.                'Start 'EvtStr.i
  129.                Say ""
  130.                Call Log "Event "||EvtDsc.i||" started."
  131.           End
  132.           Else Do
  133.                If Debug Then Say "Event #"i" in "EvtTim.i-t" minute(s)"
  134.           End
  135.      End
  136.  
  137.      If Debug Then Say "Back to sleep for 30 seconds."
  138.      rc=SysSleep(30)
  139. End
  140.  
  141. /**********************************************************************/
  142. /* Log(<chaîne>)                                                      */
  143. /**********************************************************************/
  144. Log: Procedure Expose LogFile
  145. Parse Arg St
  146. rc=LineOut(LogFile, Date()||" "||Time()||" - "||St)
  147. rc=LineOut(LogFile)
  148. Return rc
  149.  
  150. /**********************************************************************/
  151. /* MakeTime(<heure>)                                                  */
  152. /* Returns a time compatible with Time(Minutes)                       */
  153. /**********************************************************************/
  154. MakeTime: Procedure
  155. Arg HM
  156. Parse Var HM H":"M
  157. Return (60*H)+M
  158.  
  159.