Simple Server Ping and Reboot Monitor
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