Created
September 23, 2022 10:48
-
-
Save WebFikirleri/6541de517d37454af739b6ca998fe347 to your computer and use it in GitHub Desktop.
Windows Batch File Run a Command at Specific Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ECHO OFF | |
:: SET Window Title (optional) | |
TITLE Your Cron Title | |
:: Set First Execution times | |
:: Your commands will be executed between 09:00 and 09:30 | |
SET loop1Start=15:00 | |
SET loop1End=15:30 | |
:: Set Second Execution times | |
:: Your commands will be executed between 15:00 and 15:30 | |
SET loop2Start= 09:00 | |
SET loop2End=09:30 | |
:: Waiting for 30 minutes to begin loop (60*30=1800) | |
:BEGINLOOP | |
SET tm=%time:~0,5% | |
ECHO [%tm%] Waiting for next loop... | |
TIMEOUT /T 1800 > NUL | |
SET tm=%time:~0,5% | |
GOTO LOOP1 | |
:: Checking first loop | |
:LOOP1 | |
ECHO [%tm%] Checking Loop 1 | |
IF %loop1End% GEQ %tm% ( | |
IF %loop1Start% LEQ %tm% ( | |
GOTO RUN | |
) ELSE ( | |
GOTO LOOP2 | |
) | |
) ELSE ( | |
GOTO LOOP2 | |
) | |
:: Checking second loop | |
:LOOP2 | |
ECHO [%tm%] Checking Loop 2 | |
IF %loop2End% GEQ %tm% ( | |
IF %loop2Start% LEQ %tm% ( | |
GOTO RUN | |
) ELSE ( | |
GOTO BEGINLOOP | |
) | |
) ELSE ( | |
GOTO BEGINLOOP | |
) | |
:: Running your scripts... | |
:RUN | |
ECHO [%tm%] Running... | |
:: Your codes here... | |
GOTO BEGINLOOP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment