1.

Solve : Batch file to ping equipment?

Answer»

Hi, this is my first post here so I'm hoping it doesn't sound too rediculous.

I am writing a batch file to ping equipment at various different locations, I already have it so that it can pull the first three octets of the IP based on store number but for some reason cannot get the Last octet to pull correctly from a different file USING the same style command. I was wondering if someone may be able to point me in the right direction:

The file it is pulling from is LastOctet.ini and is setup as such:

Printer,99
ScriptPro,199
Workstation1,97
etc

This is the snippet of the section that is not working, I CURRENTLY have it in it's own batch for testing purposes.

@ECHO on
cls
Title [----- : Store systems ping : -----]

Set IP_LIST=IP.ini
Set LAST_OCTET=LastOctet.ini
Set STORE=StoreNumber.ini
Set PING_OUTPUT=PingOutput.txt
Set IP=
Set OCT=

if exist %PING_OUTPUT% del %PING_OUTPUT%

:GetOct
FOR /F "eol=; " %%i in ("%LAST_OCTET%") do call :TestOct %%i

:TestOct
Set TEST_OCTET=%1%
FOR /F "eol=; tokens=1,2 delims=, " %%i in (%LAST_OCTET%) do if %%i==%TEST_OCTET% set OCT=%%j
if "%TEST_OCTET%"=="" goto OCTnotFOUND
else echo.%STORE_NUMBER% - %TEST_OCTET% - %IP%.%OCT% FOUND! >>%PING_OUTPUT%


:IPnotFOUND
:OCTnotFound
:END

and what it returns is:
if ScriptPro == set OCT=199
it does not appear to be running the comparison. I think I'm missing something really simple?

This is my first attempt at a batch file such as this.
Any help is greatly Appreciated
Thank you
Simon

if you call batch or label there are %1, %2 etc.

so change this:
Set TEST_OCTET=%1%
to
Set TEST_OCTET=%1

and try again Thank you, however I TRIED your suggestion and it is STILL returning :

if SCRIPTPRO == set OCT=199

should be if SCRIPTPRO = SCRIPTPRO SET OCT=199

Thank you again - SimonCode: [Select]@ECHO on
cls
Title [----- : Store systems ping : -----]

Set IP_LIST=IP.ini
Set LAST_OCTET=LastOctet.ini
Set STORE=StoreNumber.ini
Set PING_OUTPUT=PingOutput.txt
Set IP=
Set OCT=

cd /d "%~dp0"
if exist %PING_OUTPUT% del %PING_OUTPUT%

:GetOct
FOR /F "usebackq" %%i in ("%LAST_OCTET%") do call :TestOct %%i
goto :END

:TestOct
Set TEST_OCTET=%1
if "%TEST_OCTET%"=="" goto :OCTnotFOUND
FOR /F "tokens=1,2 delims=," %%i in (%LAST_OCTET%) do (
if "%%i"=="%TEST_OCTET%" (
set OCT=%%j
) else (
echo.%STORE_NUMBER% - %TEST_OCTET% - %IP%.%OCT% FOUND!>>%PING_OUTPUT%
)
)
goto :END

:IPnotFOUND
goto :END

:OCTnotFound
goto :END

:END



Discussion

No Comment Found