Computing.Net > Forums > Programming > Mechanix2 - Ping Batch File Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Mechanix2 - Ping Batch File Help

Reply to Message Icon

Name: vortech
Date: April 20, 2007 at 09:10:41 Pacific
OS: Windows 2003 Server
CPU/Ram: 3Ghz/4Gig
Product: HP/DL380
Comment:

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 ABC

When server B is pingable again (10 successful pings) i'd then like it to:

Execute (insert) registry file B
stop service ABC
start service ABC

Then 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



Sponsored Link
Ads by Google

Response Number 1
Name: Shr0Om
Date: April 23, 2007 at 07:07:09 Pacific
Reply:

This should work (just the ping part)
::----CODE----
@echo off

set 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=0

echo Got 10 replies
::Execute your commands
goto :eof


:ExecuteFailed
::Reset counter
set counterFailed=0

echo 10 pings failed
::Execute your commands
goto :eof


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Mechanix2 - Ping Batch File Help

Batch file help. www.computing.net/answers/programming/batch-file-help/8079.html

Help fix PING batch file www.computing.net/answers/programming/help-fix-ping-batch-file/19510.html

batch file help www.computing.net/answers/programming/batch-file-help/13830.html