1.

Solve : Help with Batch file and Output?

Answer»

I am trying to write a batch file that will read 100's if IP's from a txt file, ping each one, then output the results to a file. Each successive ping request/results should be appended to the same txt file.

Help!!! please!!

BTW -using winxp pro.if exist pings.txt del pings.txt
for /f %%I in (ips.txt) do ping %%I >> pings.txt


If you are pinging 100's of IP they expect a huge file. Your output for each ping will be similar to this.

Pinging yahoo.com [206.190.60.37] with 32 bytes of data:

REPLY from 206.190.60.37: bytes=32 time=60ms TTL=52
Reply from 206.190.60.37: bytes=32 time=64ms TTL=52
Reply from 206.190.60.37: bytes=32 time=60ms TTL=52
Reply from 206.190.60.37: bytes=32 time=63ms TTL=52

Ping statistics for 206.190.60.37:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 60ms, Maximum = 64ms, Average = 61ms

No you can narrow down you file by using -n options with ping ie like ping -n 1 to send one ping to the host -n 2 would send 2 pings and so on.

Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not
Thanks for the great replies, but it seems I am still having a problem that Imdomman was having with ping outputs.

It works from a command line but not from the batch call.

I have the file ips.txt with a single, pingable, address and here is what I get.

Ping.bat -- >
if exist pings.txt del pings.txt
for /f %%I in (ips.txt) do ping %%I >> pings.txt

Output-->
C:\pings>if exist pings.txt del pings.txt
C:\pings\pings.txt
C:\pings>for /F %I in (ips.txt) do ping %I 1>>pings.txt
C:\pings>ping 12.12.12.2 1>>pings.txt

From a Command window I can type -->
ping 12.12.12.2 >> pings12.txt

Output in pings12.txt-->
Pinging 12.12.12.2 with 32 bytes of data:
Reply from 12.12.12.2: bytes=32 time=127ms TTL=234
Reply from 12.12.12.2: bytes=32 time=125ms TTL=235
Reply from 12.12.12.2: bytes=32 time=144ms TTL=235
Reply from 12.12.12.2: bytes=32 time=124ms TTL=234

Ping statistics for 12.12.12.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:
Minimum = 124ms, Maximum = 144ms, Average = 130ms

So anyone know what the 1 is or what is causing it??

Also, when I run the complete list of IPs, I get a message in the command window that says the process cannot access the file because it is being used by another process.start your batch file with this line

@echo off
With @ Echo off the output in my ping.txt file is -->

C:\pings\pings.txt

Without @ Echo the output in my ping.txt file is -->

C:\pings>if exist pings.txt del pings.txt
C:\pings\pings.txt
C:\pings>for /F %I in (ips.txt) do ping %I 1>>pings.txt
C:\pings>ping 12.12.12.2 1>>pings.txt

The ever-present 1 again.... FYI.. I figured out the process sharing violation. It is because the batch file was named PING and PING is also a command, so I think I was confusing it. When I changed the filename to PINGBAT.bat it started to work without the sharing violation.

Now I am WAITING on the results of the complete run, and will post when complete.that 1 you saw is normal.
Quote from: erobby on July 24, 2008, 06:34:18 PM

Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

Where would I use this switch in the command/bat file?Quote from: flainstigator on July 25, 2008, 07:07:31 AM
Now I am waiting on the results of the complete run, and will post when complete.

Thanks for all the help!! The basic file runs complete now. Now to tinker and SEE what ELSE I can do to streamline the outputs.Quote from: flainstigator on July 25, 2008, 07:22:26 AM
Quote from: erobby on July 24, 2008, 06:34:18 PM
Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

Where would I use this switch in the command/bat file?

@echo off
if exist pings.txt del pings.txt
for /f %%I in (ips.txt) do (
ping -n 1 %%I | find /i "Reply" >> pings.txt
)
THANKS - You all ROCK.

Saved me tons of time and angst!!!

Quote from: Dias de verano on July 25, 2008, 07:39:25 AM
Quote from: flainstigator on July 25, 2008, 07:22:26 AM
Quote from: erobby on July 24, 2008, 06:34:18 PM
Also you can use a find to limit the list like find /i "Reply" to find only machines that are replying to your ping request or a find /i "Pinging" so show every pinged address and whether it resolves or not

Where would I use this switch in the command/bat file?

@echo off
if exist pings.txt del pings.txt
for /f %%I in (ips.txt) do (
ping -n 1 %%I | find /i "Reply" >> pings.txt
)


for /f %%b in ('ping -n 2 -a %*^| find /i "Pinging"') do echo %%b >> pings.txt

Same thing just one line


Discussion

No Comment Found