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

Mechanix2 - Ping Batch File Help

Reply to Message Icon

Original Message
Name: vortech
Date: April 20, 2007 at 09:10:41 Pacific
Subject: Mechanix2 - Ping Batch File Help
OS: Windows 2003 Server
CPU/Ram: 3Ghz/4Gig
Model/Manufacturer: 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


Report Offensive Message For Removal


Response Number 1
Name: Shr0Om
Date: April 23, 2007 at 07:07:09 Pacific
Subject: Mechanix2 - Ping Batch File Help
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Mechanix2 - Ping Batch File Help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge