Since nobody offered a solution so far ... I created the script to wait.
It uses robocopy as mentioned in the other post.
The start time to wait must be set before the first execution time.
But it should at least be smaller or equal.
The break time and the last possible execution time must also be stated.
If a waiting time is to be used over midnight, the head must be rewritten.
unfortunately I have not inserted yet - sorry ...
Code: Select all
@echo off
@set prompt=$g$s
setlocal
echo Start this batch at %time%
set run= ping localhost -n 25 ^& echo(
rem "Time=HHmm" : [0700]
rem before this time Batch NOT process NOR Pause
set "startTimerBatch=0700"
rem minimum Time to Batch process
set "startProgramBatch=0800"
rem next startTime in Minutes
set /a pauseMin =60
rem "Time=HHmm" : [1156]
rem maximum Time to Batch process
set "stopTimerBatch=1800"
:Timestamp
for /f "eol=D tokens=1-6 delims=/: " %%T in (
'robocopy /L /njh "\|" .^|find "123" '
) do set "nowTime=%%W%%X"
:: ---------------------------------------------------
if 1%startTimerBatch% gtr 1%nowTime% (
echo time is NOT arrived ...
pause
exit /b 2
)
set "nextTime=%nowTime%"
set "startProgram=%startProgramBatch%"
set "startPause=%stopTimerBatch%"
set "param3=run"
goto :checkStopTime
:nextPause
call :TimedPause %startProgram% %startPause% %param3%
if errorlevel 1 (
echo Program exit.
pause
exit /b 0
)
for /f "eol=D tokens=1-6 delims=/: " %%T in (
'robocopy /L /njh "\|" .^|find "123" '
) do set /a "nowNext= 60 *1%%W + 40%%X -10000 +pauseMin, nextTime= (nowNext /60 %%24 +100) *100 +nowNext %%60"
rem call/execute program X
%run%
set "nextTime=%nextTime:~1%"
set "startProgram=%nextTime%"
:: set "startPause=%startTimerBatch%"
set "startPause="
set "param3="
:checkStopTime
if 1%stopTimerBatch% lss 1%nextTime% (
echo Time is over ...
pause
exit /b 0
)
echo continue ...
goto :nextPause
:: -------------------------------------------------------
:TimedPause ExecutionStartTime [ExecutionEndTime] [run]
::
setlocal
set "exitcode=1"
set "endTime="
for %%i in (%~2 %~3) do if /i %%i == run (set "exitcode=0") else set "endTime=%%i"
if NOT defined endTime (
for /f "eol=D tokens=1-6 delims=/: " %%T in (
'robocopy /L /njh "\|" .^|find "123" '
) do set /a "nowBefore= 60 *1%%W +40%%X -10001, endTime=(nowBefore /60 %%24 +100) *100 +nowBefore %%60"
)
set "RC=%temp%\RC_%time::=%_tmp.log"
type nul >"%RC%"
robocopy . . " Zeitfenster ." /RH:%~1-%endTime:~-4% /L /W:1 /R:1 /nFL /nDL /njH /njS /tee /Log:"%RC%" | (
for /f "tokens=1*" %%a in ('find "..." ^^^<"%RC%"') do @(
echo Zeit fuer eine Pause %time%
>&3 echo start Pause %time%
echo Program - %%b
>&3 echo Program - %%b
) >> D:\Log.txt
) && (
echo pause ends
rem start programm
del "%RC%"
exit /b 0
) || (
echo No Pause
del "%RC%"
exit /b %exitcode%
)