JSI Tip 0888. General purpose scheduling routine.

Jerold Schulman

December 3, 1998

1 Min Read
ITPro Today logo in a gray background | ITPro Today

I have scripted a genral purpose routine to allow a scheduled job to auto-repeat every n seconds and to terminate at a specific time.

JSISched.bat can be invoked by the Scheduler or submitted normally. The syntax is:

JSISched batchfile.bat SleepSecs EHH EMM     where:

batchfile.bat is the full path to the batch file you wish to repeat. It must not have an exit command.

SleepSecs is the number of seconds JSISched should wait after batchfile.bat termination before resubmitting it.

EHH and EMM is the time (Hour and minute) that the batch should cease to be resubmitted.

Example: To schedule c:toolstest.bat to run every 15 minutes ( 900 seconds ) on Monday, Tuesday, Wednesday, Thursaday, Friday, Saturday, and Sunday from 20:00 through 02:00 (date roll-over is automatically handled, when required):

AT 20:00 /EVERY:m,t,w,th,f,s,su cmd /c "JSISched c:toolstest.bat 900 02 00"

JSISched.bat uses JSIToday, JSIDateM (amended 04-Dec-98), and JSITimeM (amended 04-Dec-98).

JSISched.bat contains:

<p>@echo off<br>if exist %1 goto bok<br>:syntax<br>@echo Syntax: JSISched <drive:>
    <folder>batchfile.bat SleepSecs EHH EMM<br>goto end<br>:bok<br>if not "%5"</folder>
  </drive:>
</p><p>"" goto syntax<br>if "%4"</p>"" goto syntax
set snooze="%2"
set snooze=%snooze:"0=%
set snooze=%snooze:"=%
set /a snooze=%snooze%
call JSITimeM %3 %4 + 00 00
set /a SSEC=%NSEC%
call JSIToday
set fin=%TDYY%%TDMM%%TDDD%%AHH%%AMM%
call JSITimeM
If %NSEC% LSS %SSEC% goto batch
call JSIDateM %TDYY% %TDMM% %TDDD% + 1
call JSITimeM %3 %4 + 00 00
set fin=%AYMD%%AHH%%AMM%
:batch
call %1
sleep %snooze%
call JSITimeM
call JSIToday
set now=%TDYY%%TDMM%%TDDD%%AHH%%AMM%
if "%now%" LSS "%fin%" goto batch
set SSEC=
set fin=
set now=
set snooze=
:end

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like