From d246252166729c54b74a1bda4fe88cb552a852a1 Mon Sep 17 00:00:00 2001 From: Shashank Chattopadhyaya Date: Wed, 5 Jul 2017 17:42:59 +0530 Subject: [PATCH 1/4] File Manipulation Added call to a new bat file rmvhdrs to read the consolidated log file. Presently this bat file reads the consolidated log file and echoes to another file. Next step - remove headers. --- dos/getcflog.bat | 12 ++++++++++-- dos/rmvhdrs.bat | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 dos/rmvhdrs.bat diff --git a/dos/getcflog.bat b/dos/getcflog.bat index d0d93fa..41be673 100644 --- a/dos/getcflog.bat +++ b/dos/getcflog.bat @@ -101,7 +101,9 @@ @if %ERRORLEVEL% NEQ 0 set errormessage="Problem executing gzip. " @if %ERRORLEVEL% NEQ 0 goto errormsg1 -@copy *.log cf-logs.%ts%.txt +@set tempfile=cf-logs.temp.%ts%.txt + +@copy *.log %tempfile% @if %ERRORLEVEL% NEQ 0 set errormessage="Unable to copy files. " @if %ERRORLEVEL% NEQ 0 goto errormsg1 @@ -109,6 +111,12 @@ @if %ERRORLEVEL% NEQ 0 set errormessage="Unable to delete files. " @if %ERRORLEVEL% NEQ 0 goto errormsg1 +@set ofile=cf-logs.%ts%.txt + +@call rmvhdrs %tempfile% %ofile% +@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to generate output file. " +@if %ERRORLEVEL% NEQ 0 goto errormsg1 + @cd.. @@ -116,7 +124,7 @@ @rem $$ OUTPUT $$ @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -@move %tempfolder%\cf-logs.%ts%.txt cf-logs.%ts%.txt +@move %tempfolder%\%ofile% %ofile% @if %ERRORLEVEL% NEQ 0 set errormessage="Unable to move files. " @if %ERRORLEVEL% NEQ 0 goto errormsg2 diff --git a/dos/rmvhdrs.bat b/dos/rmvhdrs.bat new file mode 100644 index 0000000..60ae342 --- /dev/null +++ b/dos/rmvhdrs.bat @@ -0,0 +1,10 @@ +@echo off +SETLOCAL DisableDelayedExpansion +FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %1"`) do ( + set "var=%%a" + SETLOCAL EnableDelayedExpansion + set "var=!var:*:=!" + echo(!var! >> %2 + ENDLOCAL +) +) \ No newline at end of file From 0053442b9d17d5e6aa66da136d4575c16de684e4 Mon Sep 17 00:00:00 2001 From: Shashank Chattopadhyaya Date: Thu, 6 Jul 2017 16:03:15 +0530 Subject: [PATCH 2/4] The Output is now produced without headers. All records that start with a # symbol are now removed from the output file. --- dos/rmvhdrs.bat | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/dos/rmvhdrs.bat b/dos/rmvhdrs.bat index 60ae342..9d6417e 100644 --- a/dos/rmvhdrs.bat +++ b/dos/rmvhdrs.bat @@ -1,10 +1,36 @@ +@rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ +@rem $$ $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ PURPOSE $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ $$ +@rem $$ REMOVES HEADER RECORDS FROM THE CONSOLIDATED LOG FILE. $$ +@rem $$ THIS BAT FILE REMOVES THE RECORDS THAT STARTS WITH A # $$ +@rem $$ SYMBOL AT THE FIRST POSITION. $$ +@rem $$ $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ SYNTAX $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ $$ +@rem $$ RMVHDRS INPUT_CONSOLIDATED_LOG_FILE OUTPUT $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ OUTPUT $$ +@rem $$ ---------------------------------------------------------- $$ +@rem $$ $$ +@rem $$ FILE: $$ +@rem $$ THE CONTENT IS SAME AS THE INPUT FILE, WITHOUT $$ +@rem $$ THE HEADER RECORDS. $$ +@rem $$ $$ +@rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ + @echo off SETLOCAL DisableDelayedExpansion FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %1"`) do ( set "var=%%a" SETLOCAL EnableDelayedExpansion set "var=!var:*:=!" - echo(!var! >> %2 + set "frstsmbl=!var:~0,1!" + if "!frstsmbl!" NEQ "#" echo(!var! >> %2 ENDLOCAL ) ) \ No newline at end of file From ce39d6d27c6e1989e5f8b1d0994f09afd57566e0 Mon Sep 17 00:00:00 2001 From: Shashank Chattopadhyaya Date: Thu, 6 Jul 2017 17:10:16 +0530 Subject: [PATCH 3/4] Corrected Issue: temp file was not getting deleted --- dos/getcflog.bat | 32 +++++++++++++++++++------------- dos/rmvhdrs.bat | 1 - 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/dos/getcflog.bat b/dos/getcflog.bat index 41be673..513e96f 100644 --- a/dos/getcflog.bat +++ b/dos/getcflog.bat @@ -111,32 +111,38 @@ @if %ERRORLEVEL% NEQ 0 set errormessage="Unable to delete files. " @if %ERRORLEVEL% NEQ 0 goto errormsg1 -@set ofile=cf-logs.%ts%.txt +@cd.. -@call rmvhdrs %tempfile% %ofile% -@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to generate output file. " -@if %ERRORLEVEL% NEQ 0 goto errormsg1 -@cd.. +@move %tempfolder%\%tempfile% %tempfile% +@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to move files. " +@if %ERRORLEVEL% NEQ 0 goto errormsg2 + +@rem delete the temporary folder. +@rem ---------------------------- +@rmdir %tempfolder% +@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to delete directory. " +@if %ERRORLEVEL% NEQ 0 goto errormsg +@set ofile=cf-logs.%ts%.txt + @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ @rem $$ OUTPUT $$ @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -@move %tempfolder%\%ofile% %ofile% -@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to move files. " -@if %ERRORLEVEL% NEQ 0 goto errormsg2 +@call rmvhdrs %tempfile% %ofile% +@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to generate output file. " +@if %ERRORLEVEL% NEQ 0 goto errormsg @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ - -@rem delete the temporary folder. -@rem ---------------------------- -@rmdir %tempfolder% -@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to delete directory. " +@del %tempfile% +@if %ERRORLEVEL% NEQ 0 set errormessage="Unable to delete file. " @if %ERRORLEVEL% NEQ 0 goto errormsg + + @rem job finished. Time to rest! @rem ---------------------------- goto endofjob diff --git a/dos/rmvhdrs.bat b/dos/rmvhdrs.bat index 9d6417e..15b8d11 100644 --- a/dos/rmvhdrs.bat +++ b/dos/rmvhdrs.bat @@ -33,4 +33,3 @@ FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ %1"`) do ( if "!frstsmbl!" NEQ "#" echo(!var! >> %2 ENDLOCAL ) -) \ No newline at end of file From c5ce95d1b03e793549ba2750a985ef7e9b51ff42 Mon Sep 17 00:00:00 2001 From: Shashank Chattopadhyaya Date: Thu, 6 Jul 2017 17:32:36 +0530 Subject: [PATCH 4/4] Update to ReadMe 1. ReadMe updated 2. echo set to off at the start of getcflog.bat 3. echo suppressed in reseterrorlevel.bat --- README.md | 2 +- dos/getcflog.bat | 2 ++ dos/reseterrorlevel.bat | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4dd6ea..f6f9517 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The following needs to be completed before using this cmd: 2. AWS CLI and gzip must be installed. 3. The path where _aws.exe_ and _gzip.exe_ are installed must be included in the PATH system variable. 4. AWS configure must be run and the access keys and region must be set. -5. Copy the files _getcflog.bat_, _reseterrorlevel.bat_ and _settimestamp.bat_ from this git to the folder where you would like to generate the CloudFront log file. +5. Copy the files from the _dos_ folder of this git to the folder where you would like to generate the CloudFront log file. ___ diff --git a/dos/getcflog.bat b/dos/getcflog.bat index 513e96f..bfac173 100644 --- a/dos/getcflog.bat +++ b/dos/getcflog.bat @@ -52,6 +52,8 @@ @rem $$ $$ @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ +@echo off + @set errormessage= @call reseterrorlevel diff --git a/dos/reseterrorlevel.bat b/dos/reseterrorlevel.bat index ca70341..5c64936 100644 --- a/dos/reseterrorlevel.bat +++ b/dos/reseterrorlevel.bat @@ -19,4 +19,4 @@ @rem $$ $$ @rem $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ -exit /b 0 +@exit /b 0