Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 testecho.
echo This program will ping each server in turn and display the results
echo.
pausecls
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

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

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

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