Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by iamdieter
at 2024-07-10 00:54:15
Point:500 Replies:12 POST_ID:828942USER_ID:11839
Topic:
MS DOS;;
Good day
I need to do a continuous ping with a timestamp and record the results in a text file. I know the command to do the ping and write the results to a text file, but I need to record the date and time as well.
I have the following so far:
ping 127.0.0.1 >> c:Text.txt -t
How do I add the time stamp?
A simple batch file will do please
I need to do a continuous ping with a timestamp and record the results in a text file. I know the command to do the ping and write the results to a text file, but I need to record the date and time as well.
I have the following so far:
ping 127.0.0.1 >> c:Text.txt -t
How do I add the time stamp?
A simple batch file will do please
Expert: duncanb7 replied at 2024-07-10 04:34:52
Thanks for your points
Have a nice day
Duncan
Have a nice day
Duncan
Expert: duncanb7 replied at 2024-07-10 04:32:51
if you need time format to hh:mm:ss,
please replace %time% with
%time:~0,2%:%time:~3,2%:%time:~6,2%, and try the following code
please replace %time% with
%time:~0,2%:%time:~3,2%:%time:~6,2%, and try the following code
@echo offecho >pinglog.txtfor /f "tokens=*" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %%A>>pinglog.txt && GOTO Ping):Pingfor /f "tokens=* skip=2" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>pinglog.txt && GOTO Ping) 1:2:3:4:5:
Expert: duncanb7 replied at 2024-07-10 04:26:18
it will delete the file pinglog.txt at the beginning and run ping with timestamp, so it works at the following code
Duncan
Duncan
@echo offecho >pinglog.txtfor /f "tokens=*" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %%A>>pinglog.txt && GOTO Ping):Pingfor /f "tokens=* skip=2" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %date% %time% %%A>>pinglog.txt && GOTO Ping) 1:2:3:4:5:
Expert: oBdA replied at 2024-07-10 04:23:36
Try this; this only logs status changes:
@echo offsetlocal enabledelayedexpansion(set LogDelim= )if "%~1"=="" ( echo Syntax: %~nx0 ^<Computer^> pause&goto :eof)if /i "%~1"=="/start" (goto Start) else (start "Ping %~1" "cmd.exe" /c ""%~f0" /start "%~1""&goto :eof):Startset Computer=%~2set LogFile=%~dpn0_%Computer%.logmode con cols=40 lines=25set StatusOld=set Color[UP]=2Fset Color[DOWN]=4F:loop ping.exe -4 -n 1 %Computer% | find /i "TTL" >NUL if errorlevel 1 (set StatusNew=DOWN) else (set StatusNew=UP) if not "%StatusOld%"=="%StatusNew%" ( color !Color[%StatusNew%]! echo %Date% %Time%: %StatusNew% >>"%LogFile%" echo %Computer%%LogDelim%%Time%%LogDelim%%StatusNew% set StatusOld=%StatusNew% ) if "%StatusNew%"=="UP" (ping.exe -4 -n 2 -w 500 localhost >NUL)goto :loop 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:
Accepted Solution
Expert: duncanb7 replied at 2024-07-10 04:21:17
500 points EXCELLENT
Now I might know what your need is, please try this code
pinglog.bat
pinglog.bat
@echo offdel pinglog.txtfor /f "tokens=*" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %%A>>pinglog.txt && GOTO Ping):Pingfor /f "tokens=* skip=2" %%A in ('ping 127.0.0.1 -n 1 ') do (echo %date% %time% %%A>>pinglog.txt && GOTO Ping) 1:2:3:4:5:
Author: iamdieter replied at 2024-07-10 03:42:55
Hi Duncan
Still not working. What I want to achieve is to see the date and time with each ping. That way I will be able to determine exactly what time there was a packet loss, for example:
10/07/2014 14:48:06 Reply from ...
10/07/2014 14:48:07 Reply from ...
10/07/2014 14:48:08 Request timed out
10/07/2014 14:48:09 Reply from ...
10/07/2014 14:48:10 Reply from ...
I hope the above makes sense
Still not working. What I want to achieve is to see the date and time with each ping. That way I will be able to determine exactly what time there was a packet loss, for example:
10/07/2014 14:48:06 Reply from ...
10/07/2014 14:48:07 Reply from ...
10/07/2014 14:48:08 Request timed out
10/07/2014 14:48:09 Reply from ...
10/07/2014 14:48:10 Reply from ...
I hope the above makes sense
Expert: duncanb7 replied at 2024-07-10 03:12:39
@echo off
echo %date% %time%>ping.txt
ping 127.0.0.1 -n 10 >>ping.txt
Be reminded ">" operator is different from ">>" operator.
The timestamp will be on the first line of output text file
">" is created a new file and put the text into file
">>" the text is enhanced into the file if file existed
Duncan
echo %date% %time%>ping.txt
ping 127.0.0.1 -n 10 >>ping.txt
Be reminded ">" operator is different from ">>" operator.
The timestamp will be on the first line of output text file
">" is created a new file and put the text into file
">>" the text is enhanced into the file if file existed
Duncan
Author: iamdieter replied at 2024-07-10 03:08:14
Hi Mohammed
There is no timestamp, please see attached
There is no timestamp, please see attached
Expert: Mohammed Khawaja replied at 2024-07-10 02:50:32
The script I put in will work for you. You could schedule it to run via scheduled tasks and have it stop by selecting the option to terminate if the task runs for x numbers of hours or minutes.
Author: iamdieter replied at 2024-07-10 02:47:02
Hi Duncan
The ping needs to be continuous and run over a period of time. I want to see if there were any packets loss during the time it ran.
I want to achieve something like this:
10/07/2014 14:48:06.28 Request timed out.
The ping needs to be continuous and run over a period of time. I want to see if there were any packets loss during the time it ran.
I want to achieve something like this:
10/07/2014 14:48:06.28 Request timed out.
Expert: duncanb7 replied at 2024-07-10 01:29:12
p.bat============@echo offecho %date% %time%>ping.txtping 127.0.0.1 >>ping.txt 1:2:3:4:5:
you can do continuous ping with specifiy numer of time for ping you want, for example, 10 times
@echo off
echo %date% %time%>ping.txt
ping 127.0.0.1 -n 10 >>ping.txt
Hope understand your question completely.if not, please point it out
Duncan
Expert: Mohammed Khawaja replied at 2024-07-10 01:28:15
Write a batch file that does the following:
Echo Ping Records > pinglog.txt
:pingrecords
Date /t >> pinglog.txt
Ping -n 1 x.x.x.x >> pinglog.txt
Goto pingrecords
Echo Ping Records > pinglog.txt
:pingrecords
Date /t >> pinglog.txt
Ping -n 1 x.x.x.x >> pinglog.txt
Goto pingrecords