I am using the following batch script:
@echo off
set host=upc.hu
set logfile=%host%.log
echo. >> %logfile%
for /f "tokens=*" %%A in ('ping %host% -n 1 ') do (echo %%A>>%logfile% && GOTO Ping)
:Ping
for /f "tokens=* skip=2" %%A in ('ping %host% -n 1 ') do (
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
GOTO Ping)
I need to add the date in YMD format and the time in HM format e.g:`
2017.06.02 12:39 Log_%host%.log (Would prefer 20170602 1239 format)
Tried to set the date and add it to the logfile name but I have some kind of problem with the syntax because only the the year added or nothing at all. Could you help me with the script?
EDIT:
Tried to add only %date% to the logfile like this:
set logfile=%date%.log
If I simply echo the date it works just fine but the file name is 2017 without the month, day and .log part.