Batch script to test if a server is responding using Ping

Filed under Microsoft

We were asked by a client to write a simple batch program that tests if a server is alive by using ping.

Below is a sample of the script that we created. The client used it in a Formscape project to ensure that a server was available before writting a record to a database using ODBC.

@echo off
echo Testing if host is alive
ping | find "Reply" > nul
if not errorlevel 1 (
echo Host is alive
) else (
echo host is down - retry in 30 Seconds 
REM Poor man's sleep function - ping localhost
ping -n 1 -w 30000 >NUL
echo Retry now

Post a Comment

Your email is never published nor shared. Required fields are marked *