Thursday, December 10, 2020

Log ping output with timestamp

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

 

No comments:

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04 I am planning to run qemu-system-ppc to play around QEMU ...