Log ping output with a timestamp to a file. This will create a new log file every hour.
@echo off
SETLOCAL EnableDelayedExpansion
REM set /p host=host Address:
set host=%1
echo Host target : %host%
:Ping
for /F "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
REM Get the hour
SET X=%time:~0,2%
REM Remove space
SET "X=!X: =!"
REM Pad with zero
SET PADDED=0!X!
REM Get the last 2 chars
SET PADDED=!PADDED:~-2!
REM Get the expanded value
SET CURVAL=!PADDED!
SET logfile=log_!date:~10,4!-!date:~4,2!-!date:~7,2!_!CURVAL!.log
echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A>>!logfile!
echo %date% %time:~0,2%:%time:~3,2%:%time:~6,2% %%A
timeout 1 >NUL
rem GOTO END
GOTO Ping
)
:END
Reference:
https://stackoverflow.com/questions/24906268/ping-with-timestamp/40591307#40591307
Comments