The script in its current form
@echo on
setlocal EnableDelayedExpansion
set /p ipAddress="enter ip address: "
rem right now the loop is set to (1,1,50) for the sake of testing
for /l %%i in (1,1,50) do (
ping -n 1 %ipAddress%.%%i | find "TTL" > nul
if !errorlevel! == 0 (
deploy_mir.bat %ipAddress%.%%i
)
)
endlocal
and then the result of running it on a known to be online host (10.167.194.22) is
C:\DOCUME~1\socuser2\MIR>test.bat
C:\DOCUME~1\socuser2\MIR>setlocal EnableDelayedExpansion
C:\DOCUME~1\socuser2\MIR>set /p ipAddress="enter ip address: "
enter ip address: 10.167.194
C:\DOCUME~1\socuser2\MIR>for /L %i in (22 1 50) do (
ping -n 1 10.167.194.%i | find "TTL" 1>nul
if !errorlevel! == 0 (deploy_mir.bat 10.167.194.%i )
)
C:\DOCUME~1\socuser2\MIR>(
ping -n 1 10.167.194.22 | find "TTL" 1>nul
if !errorlevel! == 0 (deploy_mir.bat 10.167.194.22 )
)
"Mir Agent deployment to: 10.167.194.22"
Now that last line there means that !errorlevel! == 0 (ie, "TTL" was indeed found) so up to this point it looks like the script is working. However on the next loop, 10.167.194.23 (alive) got skipped as well as .30 and .46 . I decided to add
echo %errorlevel%
at the end of the loop to see whats going on here. Apparently, after every ping %errorlevel% was 0 so clearly
ping -n %ipAddress%.%%i | find "TTL" >nul
is where my issue is. According to this statement, "TTL" is being found after every ping, which is false, between 10.167.194.22-.50 only 3 machines are alive.
by the way, when i do
!errorlevel! == 0
what does that mean?
Everything below this line is as of 4/26/12
So my new script looks like this
@echo on
set /p ipAddress="enter ip address: "
set i=
for /l %%i in (1,1,255) do (
ping -n 1 %ipAddress%.%%i> test.txt
find "TTL" test.txt
if %errorlevel% == 0 (
deploy_this.bat %ipaddress%.%%i
)
i first tried the script without the if errorlevel check, and it worked fine. It started pinging the ip address that i provided and proceeded to .2 .3 .4 .5 and so on.
once i added this however...
if %errorlevel% == 0 (
deploy_this.bat %ipaddress%.%%i
)
this is what happens
C:\DOCUME~1\socuser2\MIR>test.bat
C:\DOCUME~1\socuser2\MIR>set /p ipAddress="enter ip address: "
enter ip address: 10.167.201
C:\DOCUME~1\socuser2\MIR>set i=
C:\DOCUME~1\socuser2\MIR>
and the script just stops dead. any ideas?