pipe a ping to a text file and have it make a new txt file every 1 MB.

I'm piping a ping to a text file on the desktop for monitoring purpose. I'd like to have it make a new text file every 'x' amount of size.

Any ideas how to do this easily in the same CMD window?
BryceRichertAsked:
Who is Participating?

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

x
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.

dmeerenCommented:
Size of 1 MB is diffucult, why not split the files on the number of times a ping is done, see this code:
@echo off

Set lognr=1

:start
Set Count=1
:LOOP
Net Send * Hello
Set /A Count=%Count%+1
ping 10.30.0.100 -n 1 >>"PingLog-%lognr%-%DATE%.txt"
echo TIME:%time% >>"PingLog-%lognr%-%DATE%.txt"
If %Count% lss 1000 GoTo :LOOP

Set /A lognr=%lognr%+1
goto start

Open in new window

0
dmeerenCommented:
Sorry, wrong code, this is the correct one:
@echo off

Set lognr=1

:start
Set Count=1
:LOOP
Set /A Count=%Count%+1
ping 10.30.0.100 -n 1 >>"PingLog-%lognr%-%DATE%.txt"
echo TIME:%time% >>"PingLog-%lognr%-%DATE%.txt"
If %Count% lss 1000 GoTo :LOOP

Set /A lognr=%lognr%+1
goto start

Open in new window

0
BryceRichertAuthor Commented:
Do I just paste that into a CMD window and hit enter?
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

dmeerenCommented:
No, you make a new file ping.bat, then you right click it, and select edit with left mouse button. And then paste the code into that file.

Or you use the file i attached
0
dmeerenCommented:
Expert exchange does not support .bat files ;-(
0
Bill PrewCommented:
Here's an approach that will handle the flip when 1MB size exceded.  Take a look and let me know what questions you have. Save this as a BAT file and run.

@echo off

REM Define base name for logfiles, and max size allowed
set LogBase=%USERPROFILE%\Desktop\PingLog-
set MaxSize=1000000

REM Get a name for the first log file
call :GetNewLogName

REM Main loop to ping and log, and check size of log file
:PingLoop
  ping localhost >>"%LogName%"
  REM If log file too big, flip to a new one
  for %%A in ("%LogName%") do (
    if %%~zA GTR %MaxSize% call :GetNewLogName
  )
  goto :PingLoop

REM Safety measure to exit before subroutines just in case
exit /b

REM Subroutine to generate log file name with YYYYMMDD and HHMMSS in it
:GetNewLogName
  set YYYYMMDD=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%
  set zTime=%TIME: =0%
  set zTime=%TIME::=%
  set HHMMSS=%zTime:~0,6%
  set LogName=%LogBase%%YYYYMMDD%-%HHMMSS%.txt
  exit /b

Open in new window

~bp
0

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
dmeerenCommented:
You Mean
%%~zA

Open in new window

reads the size of the file?
0
Bill PrewCommented:
Yes.

~bp
0
dmeerenCommented:
Thanks for that!
0
BryceRichertAuthor Commented:
when I run that bat it is making a bunch of files with nothing in them with this name that progresses by one:  PingLog-20110327-203218.txt
0
aavictorCommented:
a new text file every 'x' amount of size.

What is your meaning of every X amount of size?
example,  is it file size (or number of rows/ reply records)
                is it packet size of ping?
                is it to say 5KB of file?
                Or something you need to clarify.
However, what's your major purpose of ping test
Is it your PC? or client's PC? or Servers?
Why the size is more important than the connection issue? test us first
0
Bill PrewCommented:
==> when I run that bat it is making a bunch of files with nothing in them with this name that
==> progresses by one:  PingLog-20110327-203218.txt

Can you post the script that you are currently running, with any changes made to it.  I tested this here and it seemed to flip okay.

~bp
0
BryceRichertAuthor Commented:
I just don't want to have to open txt files that are 50 megs or larger. I just want them to be manageable.

The .bat I ran was wtih this: (no changes)

@echo off

REM Define base name for logfiles, and max size allowed
set LogBase=%USERPROFILE%\Desktop\PingLog-
set MaxSize=1000000

REM Get a name for the first log file
call :GetNewLogName

REM Main loop to ping and log, and check size of log file
:PingLoop
  ping localhost >>"%LogName%"
  REM If log file too big, flip to a new one
  for %%A in ("%LogName%") do (
    if %%~zA GTR %MaxSize% call :GetNewLogName
  )
  goto :PingLoop

REM Safety measure to exit before subroutines just in case
exit /b

REM Subroutine to generate log file name with YYYYMMDD and HHMMSS in it
:GetNewLogName
  set YYYYMMDD=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%
  set zTime=%TIME: =0%
  set zTime=%TIME::=%
  set HHMMSS=%zTime:~0,6%
  set LogName=%LogBase%%YYYYMMDD%-%HHMMSS%.txt
  exit /b
0
dmeerenCommented:
Run mine! Run Mine! ;-)
0
Bill PrewCommented:
Hmm, I just retested this here and it worked exactly as expected.  The output of each PING is in the file, and at 1000000 bytes it started a new file.

Is there anything "interesting" about the system you are running this on?

And you are looking on the desktop for the output files, right?

~bp
0
dmeerenCommented:
No, Just some fun. "No fun, no glory"
0
BryceRichertAuthor Commented:
Windows 2008. I'll try it on a windows xp machine.
0
BryceRichertAuthor Commented:
I tried it on my xp desktop and it makes a log of 0 kb sized txt files in the same manner.

I just take that text, put it on my desktop as a txt file, rename the .txt ending to .bat and run it.
0
BryceRichertAuthor Commented:
What variables do I need to adjust in the .bat file? Where in that script do I set the destination ping?

thanks.
0
Bill PrewCommented:
When it runs, does it open a black box while it's running, and are there any messages displayed there?

You can adjust this line if needed, to specify the location and base name for the log file.

set LogBase=%USERPROFILE%\Desktop\PingLog-

You can adjust this line to customize the PING for your needs, I just had it hitting localhost.

ping localhost >>"%LogName%"

~bp
0
BryceRichertAuthor Commented:
so I can change ping localhost >>"%LogName%"

 to ping 192.168.x.x >>"%AnyFileName%"?
0
aavictorCommented:
Understand this command first
Simple example
ping 192.168.1.10 -n 11000 >  output.txt

You pings this IP in 1000 times within a period of time, and you put them in an output.txt in
current directory.  This command PING can do itself.  

Next,
For /L %i in (1,1,10) do @ping 192.168.1.10 -n 1000 > %i.txt
You pings this IP in 1000 times within a period of time, and you put them in an output.txt in
current directory.  This time you add a looping to repeat 10 time as an example. As a
result, you will 1 to 10 of text files.

Of course, you can make infiinite, but what do it mean to you?  For system administrator or
network admin, you maybe just want to know the connection of servers if they are on-line. Or
the speed of data communication.  However, there are some freewares in windows you can
check download.com.  They do this job without scripting and make your life easy.

IF you just want to get a survey of your network, you can change these counters: ping -n and looping
counter.  And Change Start number and End number for file name.  Otherwise, you may be
create a bomb to your hard disk and stress MS WIndow File System Indexing. This is a fact before
your start.

Anyway, have fun to try
0
BryceRichertAuthor Commented:
this one seems to be working now. thanks all!
0
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
Microsoft DOS

From novice to tech pro — start learning today.