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
CLS
:RETRYPING
echo Testing if 192.168.1.1 host is alive
ping 192.168.1.1 | 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 1.0.0.0 -n 1 -w 30000 >NUL
echo Retry now
GOTO RETRYPING
)
:ENDPING
CLS
:RETRYPING
echo Testing if 192.168.1.1 host is alive
ping 192.168.1.1 | 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 1.0.0.0 -n 1 -w 30000 >NUL
echo Retry now
GOTO RETRYPING
)
:ENDPING

One Trackback
Marketing on the Internet…
What a great read thanks for all the information really enjoyed it !…