Home > Batch Scripting, Scripting, Windows > How to monitor a server reboot

How to monitor a server reboot

Often when restarting a server its nice to get a complete timeline of when the server went down and subsequently comes back up. I found this script a while back but found it lacked the later port 3389 to enable remote desktop again. I editted the following script from eric and have been using it for a very long time now.

http://www.ericwoodford.com/use_ping_to_notify_when_server_reboots

I have modified it slightly to include a program called portqry, when a server is restarted it monitors ping responses until the server goes down. It then continually pings the server until it gets a response. Once a responce on icmp is received it will query port 3389 (remote desktop) until it gets a response indicating the server is now ready to be logged into again.

you can either type rebooter “servername” or simply type rebooter and the program will ask you for the servers name.

After the jump is the code, and the zip file i have uploaded packaging it all together.

The script is available here with all the neccessary batches/programs, best to extract them to your %windir%\system32 where they can be accessed from cmd.

http://www.4shared.com/file/64988601/c29bd123/rebooter.html

echo off
 CLS
 Set A=0
 Set ServerName=%1
if not '%1'=='' goto :Pass1
 Set /p ServerName=[What is the server name?]
 if not '%ServerName%'=='' goto :Pass1
 echo Failed to get Server name..
 Goto :End
:Pass1
 Title Checking %servername%
 Echo Checking Server %ServerName% for response
 echo Check # _
 :Pass1a
 ping %ServerName% > %servername%-results.txt
 find /C "Request timed out" %servername%-results.txt > %servername%-fresults.txt
for /F "skip=1 tokens=1,2 delims=:" %%a in (%servername%-fresults.txt) DO (
 if NOT "%%b"==" 0" goto :TimedOut
 cls
 Echo Checking Server %ServerName% for response
 echo Check # %A%
 Set /A A+=1
 Goto :Pass1a
 )
 :TimedOut
 Set DownTime=%TIME%
 Title %servername% DOWN
 Echo Server Down %DownTIME% Passes: %A%
 Set B=0
 :Pass2
 ping %ServerName% > %servername%-results.txt
 find /C "Request timed out" %servername%-results.txt > %servername%-fresults.txt
 for /F "skip=1 tokens=1,2 delims=:" %%a in (%servername%-fresults.txt) DO (
 if "%%b"==" 0" set uptime=%time% & set c=0 & goto :BackUp
 CLS
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 Echo Waiting For Server to come up: %B%
 Set /A B+=1
 Goto :Pass2
 )
:BackUp
 Title %servername% Pinging
 cls
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 echo Server Pinging Again: %uptime% - Passes: %B%
 Echo Checking rdp port:
 portqry -n %servername% -q -e 3389
 Set /A C+=1
 if %errorlevel% NEQ 0 goto :backup
 del %servername%-fresults.txt
 del %servername%-results.txt
 cls
 Title %servername% UP
 Echo Checking Server %ServerName% for response
 echo Check # %A% - Server Down: %DownTime%
 echo Server Pinging Again: %uptime% - Passes: %B%
 echo RDP available @ %time% - Passes: %C%
 @echo.
 Echo Server down @ %downtime% Service restored @ %time%
 pause
 :End
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: