Batch program to know loss % after pinging

December 20, 2010 at 05:48:27
Specs: Windows XP
When I am pinging I am storing the output in a text file
ping 172.16.71.46 > d:\SMD\pingoutput.txt

pingoutput.txt contains
"
Pinging 172.16.71.46 with 32 bytes of data:
Reply from 172.16.71.46: bytes=32 time<1ms TTL=128
Reply from 172.16.71.46: bytes=32 time<1ms TTL=128
Reply from 172.16.71.46: bytes=32 time<1ms TTL=128
Reply from 172.16.71.46: bytes=32 time<1ms TTL=128
Ping statistics for 172.16.71.46:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
"
I want to write a batch program that prints the message "server down" when the loss % is not zero..

If you can read the text file "pingoutput.txt" and give the % loss in a variable, that is fine for me..


See More: Batch program to know loss % after pinging

Report •


#1
December 20, 2010 at 05:50:47
Untested:
ping 172.16.71.46 | find "(0%% loss)" >NUL || echo Server down

How To Ask Questions The Smart Way


Report •

#2
December 20, 2010 at 06:20:08
Thank you its working perfect.. how to put else condition in this to give server up if no loss

ping 172.16.71.46 | find "(0% loss)" >NUL || echo Server down


Report •

#3
December 20, 2010 at 07:02:03
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=4,7 delims=, " %%a in ('ping 172.16.71.46 ^| find "loss"') do (
if %%a neq %%b echo server down
)


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
December 20, 2010 at 07:04:50
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=4,7 delims=, " %%a in ('ping 172.16.71.46 ^| find "loss"') do (
if %%a neq %%b (echo server down) else (echo OK)
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
December 20, 2010 at 13:17:23
Still untested:
ping 172.16.71.46 | find "(0%% loss)" >NUL && echo Server up || echo Server down

How To Ask Questions The Smart Way


Report •


Ask Question