Bohack

Check In and Tune Out!
 
 
« LAN Party Bean Soup
Windows Version of the Linux / UNIX ‘which’ Command »

Simple Server Ping and Reboot Monitor

Print This Post Print This Post

I think we have all rebooted a server and then asked ourselves “Did it actually reboot?”. So we hunt through the logs for the event and then move on or reboot it again. During patch day for the servers this can be a real nag, knowing when something is back online so you can finish patching it; is key to getting the job done. So I wrote this little batch script a while ago to help keep track.

Once it’s started via the command of ‘pingmon servername’. It will echo the time it started monitoring, then the alive time of a successful ping back. Once the host goes dead, it will echo the time it went dead or lost ping. Then it will echo the time it has gone alive again and quit. Simple batch script with one purpose, to make the administrator’s life simple.

Just copy and paste the script below into notepad and save it as “pingmon.cmd”

@echo off

rem Bohack - pingmon.cmd - 2002i

set ipname=%1

if {%ipname%}=={} (GOTO :errhand)

set /a calive=0
set /a cdead=0
set /a cexit=0

echo.
echo.
echo Monitoring %ipname%
echo.
echo ** Started %date% - %time%
echo.

:loop

FOR /F “skip=3 tokens=1,2*” %%a IN (’ping -n 1 %ipname%’) DO CALL :checkdo %%a
if %cexit% EQU 1 (goto :mend)

goto :loop

:checkdo

set reply=%1
if {%reply%}=={} (goto :end)
set replytruc=%reply:~0,5%
if /I {%replytruc%}=={Reply} (goto :alive)
if /I {%replytruc%}=={Reque} (goto :dead)
goto :end

:alive

if %calive% EQU 0 (echo ** Alive %date% - %time%)
set /a calive=1
if %cdead% GTR 0 (echo ** Alive %date% - %time%) & (set /a cexit=1)

goto :end

:dead

if %cdead% LSS 1 (echo ** Dead  %date% - %time%)
set /a cdead=1

goto :end

:errhand

echo.
echo.
echo Usage PingMon {computer or IP}

:mend

echo.
echo.

:end
Bookmark and Share

Tags: Script, Windows

This entry was posted on Sunday, November 16th, 2008 at 8:36 pm and is filed under Windows.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

Leave a Reply





  • Author

    • About Bohack
    • Contact Info
  • Channels

    • Blog (1)
    • Exchange (2)
    • Ham Radio (1)
    • Homebrew (2)
    • Linux / Unix (2)
    • Mods (2)
    • Programming (3)
    • Recipes (2)
    • Scripts (5)
    • Spam (1)
    • Telco (3)
    • Virtual PC (1)
    • VMware (2)
    • Windows (11)
  • Archives

    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • June 2009
    • May 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
  • Misc

    • More Links
 

 

Copyright - Bohack 2009i