Hi,
Wondering if anyone can help, I have the following code:
echo OFF
cd c:\users\rod\desktop
echo %time% >> ping.txt
ping ***.244.137.254 -t >> ping.txt
Above prints to the text file no problems in the following format:
12:36:15.25
Pinging ***.244.137.254 with 32 bytes of data:
Reply from ***.244.137.254: bytes=32 time=58ms TTL=248
Reply from ***.244.137.254: bytes=32 time=69ms TTL=248
Reply from ***.244.137.254: bytes=32 time=60ms TTL=248
Reply from ***.244.137.254: bytes=32 time=57ms TTL=248
but what I want is the timestamp alongside the ping so I can keep tracks on when a specific latency spike has taken place like so:
12:36:15.25
Pinging 135.244.137.254 with 32 bytes of data:
Reply from 135.244.137.254: bytes=32 time=58ms TTL=248 + timestamp
Reply from 135.244.137.254: bytes=32 time=69ms TTL=248 + timestamp
Reply from 135.244.137.254: bytes=32 time=60ms TTL=248 + timestamp
Reply from 135.244.137.254: bytes=32 time=57ms TTL=248 + timestamp
Is the above possible? I have tried numerous things with no results.
Any help appreciated.
Regards,
Ross
Batch file which pings and timestamps alongside
Moderator: DosItHelp
Re: Batch file which pings and timestamps alongside
Code: Select all
@echo off
set "file=c:\users\rod\desktop\ping.txt"
set ip=www.google.com
setlocal enabledelayedexpansion
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 ^|find "TTL" ') do >> "%file%" echo %%a - !date! @ !time!&echo %%a
goto :loop
Re: Batch file which pings and timestamps alongside
foxidrive wrote:Code: Select all
@echo off
set "file=c:\users\rod\desktop\ping.txt"
set ip=www.google.com
setlocal enabledelayedexpansion
:loop
for /f "delims=" %%a in ('ping %ip% -n 1 ^|find "TTL" ') do >> "%file%" echo %%a - !date! @ !time!&echo %%a
goto :loop
Thanks foxidrive, this was exactly what I was looking for
Re: Batch file which pings and timestamps alongside
Thanks. Just be aware that this reports successful pings only.
If you also want time outs then change the
find "TTL"
to this and it should work.
find /i "reply from"
If you also want time outs then change the
find "TTL"
to this and it should work.
find /i "reply from"
Re: Batch file which pings and timestamps alongside
foxidrive wrote:Thanks. Just be aware that this reports successful pings only.
If you also want time outs then change the
find "TTL"
to this and it should work.
find /i "reply from"
Thanks, did notice that and changed it to reply, couple of quick questions, been trying to understand the code, one bit I dont understand is:
^|find
I understand | is a pipe/redirect but what is the meaning of the ^ before it? Could find nothing online.
Regards,
Ross
-
- Expert
- Posts: 1163
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Batch file which pings and timestamps alongside
It's an escape character. You need it so that the pipe is included in the thing the for loop is doing instead of everything after it being separate.
Re: Batch file which pings and timestamps alongside
Just adding here that without escaping regular pipes and redirection characters in a for in do loop command, they will generate errors.