title: run a batch file for every alive machine in a /24 network
body: <p>The script in its current form</p>
  
  <pre><code>@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" &gt; nul
  
  if !errorlevel! == 0 (
  deploy_mir.bat %ipAddress%.%%i
  
  )
  )
  
  endlocal
  </code></pre>
  
  <p>and then the result of running it on a known to be online host (10.167.194.22) is</p>
  
  <pre><code>C:\DOCUME~1\socuser2\MIR&gt;test.bat
  
  C:\DOCUME~1\socuser2\MIR&gt;setlocal EnableDelayedExpansion
  
  C:\DOCUME~1\socuser2\MIR&gt;set /p ipAddress="enter ip address: "
  enter ip address: 10.167.194
  
  C:\DOCUME~1\socuser2\MIR&gt;for /L %i in (22 1 50) do (
  ping -n 1 10.167.194.%i   | find "TTL"  1&gt;nul
  if !errorlevel! == 0 (deploy_mir.bat 10.167.194.%i )
  )
  
  C:\DOCUME~1\socuser2\MIR&gt;(
  ping -n 1 10.167.194.22   | find "TTL"  1&gt;nul
  if !errorlevel! == 0 (deploy_mir.bat 10.167.194.22 )
  )
  "Mir Agent deployment to: 10.167.194.22"
  </code></pre>
  
  <p>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 </p>
  
  <pre><code>echo %errorlevel% 
  </code></pre>
  
  <p>at the end of the loop to see whats going on here.  Apparently, after every ping %errorlevel% was 0 so clearly </p>
  
  <pre><code>ping -n %ipAddress%.%%i | find "TTL" &gt;nul
  </code></pre>
  
  <p>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.</p>
  
  <p>by the way, when i do</p>
  
  <pre><code>!errorlevel! == 0
  </code></pre>
  
  <p>what does that mean? </p>
  
  <p><strong>Everything below this line is as of 4/26/12</strong></p>
  
  <pre><code>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&gt; test.txt
  find "TTL" test.txt
  if %errorlevel% == 0 (
  deploy_this.bat %ipaddress%.%%i
  )
  </code></pre>
  
  <p>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.</p>
  
  <p>once i added this however...</p>
  
  <pre><code>if %errorlevel% == 0 (
  deploy_this.bat %ipaddress%.%%i
  )
  </code></pre>
  
  <p>this is what happens</p>
  
  <pre><code>C:\DOCUME~1\socuser2\MIR&gt;test.bat
  C:\DOCUME~1\socuser2\MIR&gt;set /p ipAddress="enter ip address: "
  enter ip address: 10.167.201
  C:\DOCUME~1\socuser2\MIR&gt;set i=
  C:\DOCUME~1\socuser2\MIR&gt;
  </code></pre>
  
  <p>and the script just stops dead. any ideas?</p>