WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: rickmds on September 21, 2014, 07:52:15 AM

Title: Multiple Scheduled Events in same Script
Post by: rickmds on September 21, 2014, 07:52:15 AM
Hi
The script below works great but I have several events @ 2 AM, 3 Am & 4 AM that fire 3 different executables.  Can anyone suggest modifications to this script below to eliminate the need to create 3 separate scripts?

Script to Launch Every Day of the Week at 11pm:

;Assuming you want to run a job M-F at 11 pm
;First wait for 11 pm

while 1
   ttt="0000:00:00:23:00:00"
   TimeWait(ttt)
   ;now see if it is m-f
   a=TimeYmdHms()
   b=TimeJulianDay(a)
   c=(b+5) mod 7
   if (c==0) || (c==6) then continue  ; if the day if Sunday or Saturday, then transfer control back to while loop for re-eval
   run("yourjob.exe","")
   TimeDelay(60)
endwhile 


Thanks in advance.
Rick
Title: Re: Multiple Scheduled Events in same Script
Post by: td on September 21, 2014, 09:45:37 AM
You could place all functionality into a single compiled script and then pass in a parameter that indicates which bits need to executed on any give start.

You also might consider using Window's built in Task Scheduler to launch your compiled script.  It has the advantage of being less likely to be inadvertently shut down.   
Title: Re: Multiple Scheduled Events in same Script
Post by: rickmds on September 21, 2014, 10:27:58 AM
Thanks for the suggestions td!  The code I put together seems to works but  from testing, the 3 event times must be in sequence.

tt1="0000:00:00:13:23:00"
  tt2="0000:00:00:13:24:00"
  tt3="0000:00:00:13:25:00"

while 1
   
   if TimeWait(tt1)
   Display(1,"tt1",tt1)
   run("notepad.exe","")
   endif

   if TimeWait(tt2)
   Display(1,"tt2",tt2)
   run("notepad.exe","")
   endif

   if TimeWait(tt3)
   Display(1,"tt3",tt3)
   run("notepad.exe","")
   endif

   TimeDelay(60)
endwhile 
Title: Re: Multiple Scheduled Events in same Script
Post by: td on September 22, 2014, 06:55:50 AM
The fact that your tasks need to be executed in sequences does not mean that entry process can be placed in a single script nor does it mean that you can use the task scheduler. In fact, if each task must complete before the next one can start, it makes more desirable to use a single script as synchronization becomes more or less automatic.