Thursday, February 19, 2015

Simple batch file to continuously ping a defined set of computers and log failures to a text file

There have been times in the past where I’ve had to set up a quick and dirty way to ping a set of servers for a period of time to determine whether any packets are lost and while there are quite a few tools available to download, I’ve preferred to use the following simple batch file:

@echo off

set logfile=F:\continuousPinglog.txt

setlocal enableDelayedExpansion

echo Starting Continuous Ping !DATE!_!TIME! >> %logfile%

goto main


:func

  ping -n 1 -w 1000 %1 1> NUL 2> NUL

  if %ERRORLEVEL%==1 echo !DATE! !TIME! Problem pinging %1 >> %logfile%

goto :end


:main

  call :func Server001
  call :func Server002
  call :func Server003
  call :func Server004
  call :func Server005
  call :func Server006

  goto :main

:end

Simply paste the commands into Notepad and save the file as a .bat file.  The log generated will display only entries of failures similar to the following output:

image

No comments: