The purpose of this bit of my script is to extract certain pieces from logs files, previously collected in this script. However, there is an entry added in %parse% per line per for condition.
What I am wanting is IF something is found in the findstr section, then input found data in desired format, into the %parse% file.
Current output is (Its not very pretty here, than it is in my log file)
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - -------------- Start c:\programdata\dctool\Data\<Removed_HostName>\MA\McScript.log -------------
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> -
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start Virus Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End Virus Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start Blocked Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End Blocked Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start Detected Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End Detected Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start Deleted Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End Deleted Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start File-cksum-mismatch Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End File-cksum-mismatch Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start encrypted Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End encrypted Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - Start Failed Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - End Failed Search
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> -
Tue 04/03/2018 - 13:51:23.19 - <Removed_UN> - <Removed_HostName> - -------------- End c:\programdata\dctool\Data\<Removed_HostName>\MA\McScript.log ------------
-
I like the first and last line of this code. That lets me know that the file was parsed. However, I dont want all the middle junk in there, unless something is found. For example, "Start encrypted search" and "End encrypted search" would only be present, had it found something.
::::::::::::::::::
:: Analyze Data ::
::::::::::::::::::
:analyze
echo %date% - %time% - %un% - %host% --- Log Parser --- >>%logfile%
echo --- Log Parser ---
echo.
for /f "tokens=*" %%a in (%filelocation%) do (
echo %date% - %time% - %un% - %host% - -------------- Start %%a ------------->>%parse%
echo %date% - %time% - %un% - %host% ->>%parse%
echo %date% - %time% - %un% - %host% - Start Virus Search >>%parse%
echo Start Virus Search
for /f "tokens=*" %%b in ('findstr /r /n "virus" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End Virus Search >>%parse%
echo End Virus Search
echo %date% - %time% - %un% - %host% - Start Blocked Search >>%parse%
echo Start Blocked Search
for /f "tokens=*" %%b in ('findstr /r /n "Blocked" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End Blocked Search >>%parse%
echo End Blocked Search
echo %date% - %time% - %un% - %host% - Start Detected Search >>%parse%
echo Start Detected Search
for /f "tokens=*" %%b in ('findstr /r /n "detected" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End Detected Search >>%parse%
echo End Detected Search
echo %date% - %time% - %un% - %host% - Start Deleted Search >>%parse%
echo Start Deleted Search
for /f "tokens=*" %%b in ('findstr /r /n "deleted" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End Deleted Search >>%parse%
echo End Deleted Search
echo %date% - %time% - %un% - %host% - Start File-cksum-mismatch Search >>%parse%
echo Start File-cksum-mismatch Search
for /f "tokens=*" %%b in ('findstr /r /n "File-cksum-mismatch" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End File-cksum-mismatch Search >>%parse%
echo %date% - %time% - %un% - %host% - Start encrypted Search >>%parse%
echo Start encrypted Search
for /f "tokens=*" %%b in ('findstr /r /n "encrypted" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End encrypted Search >>%parse%
echo End Failed Search
echo %date% - %time% - %un% - %host% - Start Failed Search >>%parse%
echo Start Failed Search
for /f "tokens=*" %%b in ('findstr /r /n "Failed" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End Failed Search >>%parse%
echo End Failed Search
echo %date% - %time% - %un% - %host% - Start inv_partial_sync Search >>%parse%
echo Start inv_partial_sync Search
for /f "tokens=*" %%b in ('findstr /r /n "inv_partial_sync" %%a') do (
echo %date% - %time% - %un% - %host% - %%b>>%parse%
)
echo %date% - %time% - %un% - %host% - End inv_partial_sync Search >>%parse%
echo End inv_partial_sync Search
echo %date% - %time% - %un% - %host% ->>%parse%
echo %date% - %time% - %un% - %host% - -------------- End %%a ------------->>%parse%
)
echo %date% - %time% - %un% - %host% - Parser log Location: %parse%>>%logfile%
echo %date% - %time% - %un% - %host% - Done Parsing>>%logfile%
echo Done Parsing
echo.
exit /b
FOR /Fcommand. You could just get rid of that and use the%filelocation%variable directly with all of your nestedFOR /Fcommands. This will also give you an accurate time and date. As it stands the date and time will be the same for every check.