Working on servers, you inveriably need to reboot them. One of the primary tools I use to determine if a server has shut down is to PING the server.
PING servername -t
This will PING the server repeatedly until I quit it. When the server goes down, it will return "Request Timed Out" instead of a valid PING response. Here is what it would look like when the server shuts down, then comes back up again.
Pinging Servername [192.168.1.1] with 32 bytes of data:
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Request timed out
Request timed out
Request timed out
Request timed out
Request timed out
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Reply from 192.168.1.1: bytes=32
Unfortunately, if you happen to miss the downtime (change screens, leave your desk, etc.) you'll never know what happened. Did the server reboot or has Windows crashed while trying to go down???
That's why I developed this little batch script. It utilizes the DOS PING command to monitor the status change. When the server successfully shuts down, it changes the display and waits for the server to come back up.
Checking Server [servername] for response
Check # 0 - Server Down: 16:32:27.89
Waiting For Server to come up: 4
Server Pinging Again Passes: 5
Highlight and copy the following code to your buffer (CTRL+C). Open notepad, and paste it into a new text file. Save that text file as PingAlive.bat. Copy this file into your system path (like C:\Windows\System32).
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
Echo Checking Server %ServerName% for response
echo Check # _
:Pass1a
ping %ServerName% > results.txt
find /C "Request timed out" results.txt > fresults.txt
for /F "skip=1 tokens=1,2 delims=:" %%a in (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%
Echo Server Down %DownTIME% Passes: %A%
Set B=0
:Pass2
ping %ServerName% > results.txt
find /C "Request timed out" results.txt > fresults.txt
for /F "skip=1 tokens=1,2 delims=:" %%a in (fresults.txt) DO (
if "%%b"==" 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
echo Server Pinging Again - Passes: %B% %TIME%
:End
Now when you reboot a server, simply open a new command window and type:
PINGALIVE SERVERNAME
Now I can use my server reboots as coffee breaks and not worry about missing anything!