Tuesday, February 06, 2007

 

Server Reboot Monitor Script

I find I'm always going through the same routine anytime I restart a server: continuous ping until it comes up and then wait for RDP to be available so that I can connect back in. So this script just puts all of that together - pings until the server goes offline, pings until the server comes back online, and then checks for RDP to be available again. That's all it does - nothing else, nothing fancy.

Just running it will show you the usage (rebootwatch server_name)


@ECHO OFF

REM Server Restart Watch script
REM Aaron Czechowski, Caveo Network Solutions, February 2007

cls

IF !%1==! GOTO Syntax

ECHO Waiting for %1 to shutdown...
:ShutdownLoop
ping %1 -n 1 > NUL 2>&1
IF %errorlevel% EQU 0 GOTO ShutdownLoop
ECHO.
ECHO %1 is not responding.

ECHO.
ECHO.
ECHO Waiting for %1 to restart...
:RestartLoop
ping %1 -n 1 > NUL 2>&1
IF %errorlevel% EQU 1 GOTO RestartLoop
ECHO.
ECHO %1 is responding.

ECHO.
ECHO.
ECHO Waiting for RDP to come alive...
:RDPLoop
portqry -n %1 -e 3389 > NUL 2>&1
IF %errorlevel% EQU 1 GOTO RDPLoop
ECHO.
ECHO %1 is listening on TCP 3389

ECHO.
ECHO.
ECHO %1 should now be ready to access again.
PAUSE

:Syntax
ECHO Usage: RebootWatch server_name
ECHO.
PAUSE

Comments:
I usually just patch my servers, reboot, and then assume everything went well and the server came back online. No need to RDP back in! ;-)
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?