Computing.Net > Forums > Programming > need help with a simple batch file

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.

need help with a simple batch file

Reply to Message Icon

Name: heardy
Date: February 17, 2005 at 01:31:04 Pacific
OS: winxp
CPU/Ram: 512
Comment:

Hi all,

I have a problem creating a batch file that allows me to test that a link is up.
This is what i have so far, i'm a beginner to this, so this may seem a little over the top:

@echo OFF
title Server test

echo.
echo This program will ping each server in turn and display the results
echo.
pause

cls
echo.
echo ***********************************
echo ** Server: intranet **
echo ***********************************
ping -n 1 10.0.0.1 > null
if errorlevel 1 echo intranet (10.0.0.1) Not Responding
if errorlevel 0 echo intranet (10.0.0.1) All OK
pause

-----------------------
echo.
echo ***********************************
echo ** Server: testing **
echo ***********************************
ping -n 1 10.0.0.87 > NULL
if errorlevel 1 echo testing (10.0.0.87) Not Responding
if errorlevel 0 echo testing (10.0.0.87) All OK
pause
------------------------
echo.
echo ***********************************
echo ** Server: file server **
echo ***********************************
ping -n 1 10.0.0.5 > NULL
if errorlevel 1 echo file server (10.0.0.5) Not Responding
if errorlevel 0 echo file server (10.0.0.5) All OK
pause
------------------------
echo.
cls
echo.
echo.
echo Server check complete!
echo.

This works OK if the link is up, but if its down it displays both messages saying that it is "not resonding", and "all ok" see below for results:


***********************************
** Server: intranet **
***********************************
intranet (10.0.0.1) All OK
Press any key to continue . . .
------

***********************************
** Server: testing **
***********************************
testing (10.0.0.87) Not Responding
testing (10.0.0.87) All OK
Press any key to continue . . .
------

***********************************
** Server: file server **
***********************************
file server (10.0.0.5) All OK
Press any key to continue . . .

can anyone tell me a way of getting round this.
any help would be appreciated




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 17, 2005 at 02:28:01 Pacific
Reply:

Hi heardy,

You're prety close.

The gotcha is that the errorlevel test evals true if the value is equal OR MORE.

So you need to modify this block:

::**
if errorlevel 1 echo intranet (10.0.0.1) Not Responding
if errorlevel 0 echo intranet (10.0.0.1) All OK
pause
::**

like so:

::**
goto %errorlevel%
:1
echo no good msg
goto :ENDtest
:0
echo OK msg
:ENDtest
pause
::**

HTH

M2


0

Response Number 2
Name: heardy
Date: February 18, 2005 at 02:53:02 Pacific
Reply:

Hi Mechanix2Go

Thanx for that it worked a treat!
You're a star!!


0

Sponsored Link
Ads by Google
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: need help with a simple batch file

Need help to make a simple batch file www.computing.net/answers/programming/need-help-to-make-a-simple-batch-file/20286.html

DOS Batch File Commands www.computing.net/answers/programming/dos-batch-file-commands/14637.html

Simple Batch file www.computing.net/answers/programming/simple-batch-file/10948.html