cmd - export server log file from event viewer and save into a folder without overwrite the file -
i want export server log file event viewer , save folder without overwrite file.
then set schedule using task schedule trigger batch file automatic periodic update. (i new in wevtuitil
, cmd
command)
example:
application_event1.evtx application_event2.evtx application_event3.evtx application_event4.evtx
here script bat file
//i export log file event viewer
wevtutil epl application e:\a\testing_application.evtx
follow script make evtx file name increase number
@echo off setlocal enableextensions enabledelayedexpansion set "source=e:\a" if exist "%source%\*.evtx" ( set increase=0 set increase=!increase!+1 ren "%source%\*.evtx" "*.!increase!.evtx" ) endlocal
result: testing_application.0+1,testing_application.0+1.0+1
you missing /a
in set
because it's arithmetic operation. more type set /?
also missing for-loop
too. more type for /?
try this.
@echo off setlocal enableextensions enabledelayedexpansion set "source=e:\a" set increase= /f "delims=" %%a in ('dir /b /a-d "%source%\*.evtx"') ( set /a increase+=1 echo ren "%%~a" "%%~na!increase!%%~xa" ) endlocal
i seem wrong in thought trying achieve.
here attempt:
@echo off set "source=e:\a" set "filename=testing_application" wevtutil epl application e:\a\testing_application.evtx /f "tokens=2 delims=-." %%a in ( 'dir /b "%source%\%filename%*.evtx" ^|sort /r ^|findstr /r [0-9]') ( set "num=%%a" goto done ) ren "%source%\%filename%.evtx" "%filename%-001.evtx" exit /b 0 :done rem :: remove zeros in front of numbers before incrementing /f "tokens=* delims=0" %%a in ("%num%") set num=%%a set /a num+=1 set incr=000%num% ren "%source%\%filename%.evtx" "%filename%-%incr:~-3%.evtx" exit /b 0
the solution found incrementing number zeros in front based on this
which zeros in front required sort
files correctly.
Comments
Post a Comment