Computing.Net > Forums > Programming > Batch file averaging

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file averaging

Reply to Message Icon

Name: keridbey
Date: February 28, 2008 at 10:13:07 Pacific
OS: WinXP
CPU/Ram: 1.83 Ghz / 1 Gb
Product: Dell
Comment:

There is a program that runs on a remote PC which does some telnet work via a script, then sends the session log to a text file. Depending on the speed of the telnet session (it's using TST10.exe), the formatting is sometimes different (usually the slower connections). I'm hoping to create a batch file that can send several pings to the device being telnetted into, add the response times together, then give an average response time. The parsing part is done:

@echo off
set IP=127.0.0.1

ping %IP% -n 1 -w 3000>.\DetermineSpeed1.txt
ping %IP% -n 1 -w 3000>.\DetermineSpeed2.txt
ping %IP% -n 1 -w 3000>.\DetermineSpeed3.txt
ping %IP% -n 1 -w 3000>.\DetermineSpeed4.txt

for /f "tokens=3 delims==" %%a in ('type .\DetermineSpeed1.txt ^| find "time"') do set One=%%a
for /f "tokens=3 delims==" %%a in ('type .\DetermineSpeed2.txt ^| find "time"') do set Two=%%a
for /f "tokens=3 delims==" %%a in ('type .\DetermineSpeed3.txt ^| find "time"') do set Three=%%a
for /f "tokens=3 delims==" %%a in ('type .\DetermineSpeed4.txt ^| find "time"') do set Four=%%a

for /f "tokens=1 delims= " %%a in ('echo %One%') do set One=%%a
for /f "tokens=1 delims= " %%a in ('echo %Two%') do set Two=%%a
for /f "tokens=1 delims= " %%a in ('echo %Three%') do set Three=%%a
for /f "tokens=1 delims= " %%a in ('echo %Four%') do set Four=%%a

for /f "tokens=1 delims=m" %%a in ('echo %One%') do set One=%%a
for /f "tokens=1 delims=m" %%a in ('echo %Two%') do set Two=%%a
for /f "tokens=1 delims=m" %%a in ('echo %Three%') do set Three=%%a
for /f "tokens=1 delims=m" %%a in ('echo %Four%') do set Four=%%a

echo First ping response : %one%
echo Second ping response: %two%
echo Third ping response : %three%
echo Fourth ping response: %four%

del .\DetermineSpeed1.txt
del .\DetermineSpeed2.txt
del .\DetermineSpeed3.txt
del .\DetermineSpeed4.txt
pause
goto:EOF

Now I just need to find a way to do the math of adding them together and dividing by the number of pings to find the average. Any takers on this challenge? :)



Sponsored Link
Ads by Google

Response Number 1
Name: keridbey
Date: February 28, 2008 at 10:27:08 Pacific
Reply:

Wow, I'm a complete knucklehead not to have figured this out.

set /a sum=%one%+%two%+%three%+%four%
echo.
echo Sum: %sum%

set /a average=%sum%/4
echo.
echo Average: %average%
echo.

Wheee!


0

Response Number 2
Name: Mechanix2Go
Date: February 28, 2008 at 23:54:15 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=4 delims==" %%a in ('ping computing.net ^|find " Average"') do (
echo %%a
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 3
Name: keridbey
Date: March 3, 2008 at 05:22:53 Pacific
Reply:

Leave it to me to write a bazillion lines of code when less than five are needed. :) Thanks!!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


ASP forms WSH: Delete files in fold...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file averaging

Batch File deleting files by date? www.computing.net/answers/programming/batch-file-deleting-files-by-date/15581.html

Batch File Exe Program on Date www.computing.net/answers/programming/batch-file-exe-program-on-date/15176.html

CALL a program with a Batch file www.computing.net/answers/programming/call-a-program-with-a-batch-file/13968.html