I'm struggeling with using the If-Else Command with the Modulo-Operator (Windows 7 CommandLine)
I would like using a command only every hour. My Batch pings out every minute , and the store the "Result" in the "myIP.csv"-File
My Batch looks like this.
@echo off
set COUNTER=0
:AGAIN
set TimeVar=%time:~0,8%
for /f "skip=4 tokens=2" %%a in ('nslookup myip.opendns.com. resolver1.opendns.com') do (set IP=%%a)
for /f "tokens=*" %%b in ('ping -n 2 8.8.8.8') do (set ANSWER=%%b)
echo %date%,%TimeVar%,%IP%,%ANSWER:~0,-1%; >> myIP_newOne.txt
SET /A COUNTER+=1
timeout 60
goto AGAIN
It should look something like this
@echo off
SET COUNTER=0
SET HOUR=60
:AGAIN
SET /a DOIT=COUNTER%%HOUR
IF %DOIT% === 0 (
CODEBLOCK-A...
CODEBLOCK-B...
) ELSE (
CODEBLOCK-A
)
timeout 60
goto AGAIN
I tried several different methods, but i can't make it work. I would like to use the "GetIP"-Command only once per hour... not every minute. Perhabs i just have some "bad formatting" in it. Not sure why it won't work.
I'll hope you understand what i mean.
Aucun commentaire:
Enregistrer un commentaire