Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Mechanix2, I need some help creating an advanced ping batch file.
What the batch file would do is this.
A batch file running on server A would continously ping server B, when 10 pings (user definable) in a row to server B fail, I need it to execute a series of commands.
They are:
Execute (insert) registry file A
stop service ABC
start service ABCWhen server B is pingable again (10 successful pings) i'd then like it to:
Execute (insert) registry file B
stop service ABC
start service ABCThen start backover again.
The insertion of the registry key and the stopping and starting of a service I miht be able to figure out, but the ping portion I'm lost.
Any help would be much appeciated.
Thanks

This should work (just the ping part)
::----CODE----
@echo offset NrOfPings=10
set counterOK=0
set counterFailed=0:Loop
ping -n 1 127.0.0.0 >nul
if errorlevel 1 (set /a counterOK=counterOK+1) else set /a CounterFailed=CounterFailed+1
echo Replies:%counterOK% Failed:%CounterFailed%
if %counterOK% GEQ %NrOfPings% call :ExecuteOK
if %counterFailed% GEQ %NrOfPings% call :ExecuteFailed
goto Loop
:ExecuteOK
::Reset counter
set counterOK=0echo Got 10 replies
::Execute your commands
goto :eof
:ExecuteFailed
::Reset counter
set counterFailed=0echo 10 pings failed
::Execute your commands
goto :eof

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |