1.

Solve : Looking for help with the > switch?

Answer»

Looking for a bit of help trying to set up a batch file, where I can PING VARIOUS servers in the company I work for . We have approx 20 we ping every morning and I can write a batch file to ping them.

What I would like to do to to direct the output of the ping to a text file so we can review and save the results of the ping of the 20 servers

What happens is the output is outputted to kr.txt file but it includes only the output from the last server on the list, in this case the output of 10.9.10.16. I could output the results of the ping to 20 different text files, but would prefer to have the output in one txt file

ping 10.9.10.1 > C:\kr.txt
ping 10.9.10.16 > C:\kr.txt

Any ideas ?

ThanksWelcome to the CH forums.

Use

Code: [Select]ping 10.9.10.1 > C:\kr.txt
ping 10.9.10.16 >> C:\kr.txt

> starts writing the file >> appends further data to the end of the file.

If you don't want to overwrite the file each day use

Code: [Select]ping 10.9.10.1 >> C:\kr.txt
ping 10.9.10.16 >> C:\kr.txt

Good luckThanks for the quick reply !!.

Was thinking of outputting the text file to a file based on the date using the var %dat%, not EXACTLY sure how to do this, so we would have a txt file called Sept 18, tomo called Sept 19 etc Following seems to do what you want if the %date% environment variable returns the date in yyyy-mm-dd format. You may have to make changes if your %date% format differs. Also you'll have to change path(s) to suit. I ran it with the Ping commands just for a trial.

Good luck.

Code: [Select]@echo off
cls

set /a mm=1%date:~5,2%-100
set /a dd=1%date:~-2%-100

for /F "tokens=%mm%" %%b in ("Jan Feb Mar Apl May Jun Jul Aug SEP Oct Nov Dec") do (
set month=%%b.txt
)

set logfile=c:\%dd%-%month%

ping -n 5 -w 100 10.9.10.1 > %logfile%
ping -n 5 -w 100 10.9.10.16 >> %logfile%
:: etc....

type c:\19-Sep.txt




Discussion

No Comment Found