ping test


can u help a simple code that runs a ping test to 3 different servers and write these results to a log file? we dont want it to append each result to the log file

all help will do
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Something like this? It'll open one command prompt for each server, will only log status changes, and (the most important feature) change the window color according to the current status.
ServerList can be host names or IP addresses; the log files will be created in the script's folder, begin with the script's name, then the pinged name.
@echo off
set ServerList=
if "%~1"=="" (
	for %%a in (%ServerList%) do (
		start "" "%~f0" %%a
	goto :eof
set IP=%~1
mode con cols=40 lines=25
title Ping %IP%
set LogFile=%~dpn0-%IP%.log
set Lost=X
ping.exe -4 -n 1 %IP% | find /i "TTL" >NUL
if errorlevel 1 (
	if not %Lost%==1 (
		color 4F
		echo - Down: %Date% %Time: =0%
		>>"%LogFile%" echo - %Date% %Time%
		set Lost=1
) else (
	if not %Lost%==0 (
		color 2F
		echo + Up: %Date% %Time: =0%
		>>"%LogFile%" echo + %Date% %Time%
		set Lost=0
	ping.exe -4 -n 2 localhost >nul
goto :loop

Open in new window

Let's assume that the servers are named Server1, Server2, and Server3, c:\log exists, and that name resolution is working.

The following should work:

ping server1 > c:\log\server1ping.txt
ping server2 > c:\log\server2ping.txt
ping server3 > c:\log\server3ping.txt

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rutgermonsAuthor Commented:
thanks comprobsolv

how can i get it only right to one file and append and not overwrite
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

NVITEnd-user supportCommented:
Hi rutgermons...

Per CompProbSolv's solution, change all to:
>> c:\log\pingresults.txt

Open in new window

Basically, use >> instead of >
Steve KnightIT ConsultancyCommented:
Glad I didn't think more complicated too oBdA!

NVIT's answer is correct if you want to keep ALL old logs.  If you want to start a new log (erasing the old one) each time you run the set of 3 tests, use > on the first one and >> on the second and third.  You could do some rename commands at the start to keep some number of old logs.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.