19 May, 2009

Smart Ping when restarting

Hi,
You restart a remote server because you installed some new MS updates and you need to know when it's back online.
What we all do?, start pinging the server and continue to do other things.
when we come back after few minutes to the ping window we see that the server is online but we missed to see it's gone offline.
The following script (I called it "Smart Ping") will check the output from the ping action and look for specific word to let you know that the server went down and went up again.

Fill free to change the words it searches as you see fit in your environment.

=======================================
echo off
cls
:dead
title Server [%1] is going to shut down [%time%]...
ping -n 1 -w 300 %1 find "Request timed out."
IF %ERRORLEVEL% == 0 (goto back_alive) ELSE (goto dead)
:back_alive
title Server [%1] is down [%time%]...
ping -n 1 -w 300 %1 find "TTL"
IF %ERRORLEVEL% == 0 (goto end) ELSE (goto back_alive)
:end
title Server [%1] is Back online [%time%]...
pause
=======================================

Enjoy...

No comments:

Post a Comment