findstr help - Dependant search strings...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

findstr help - Dependant search strings...

#1 Post by SIMMS7400 » 01 May 2017 09:25

Hi Folks -

I have a need to use findstr command, however the search strings are dependent on each other. Let me explain.

When I start this particular service, it appends content to a log file. Then, when a specific string is seen in the logs (or in the command window) I can proceed to the next step.

This is the relevant string in Admin_Server.log:

Code: Select all

####<May 01, 2017 6:01:07 AM EDT> <Notice> <WebLogicServer> <stg-hybi> <AdminServer> <main> <<WLS Kernel>> <> <f386c94cf0527dca:-6e5bd079:15bc0e10a05:-8000-000000000000000a> <1493589667102> <BEA-000360> <Server started in RUNNING mode> 


So I first need to search for today's date...Then, search for
<Server started in RUNNING mode>
after that. The reason I need to search for today's date and there are thousands of lines in this file, the only difference being the date.

How would I go about doing that?

Thank you!

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: findstr help - Dependant search strings...

#2 Post by SIMMS7400 » 01 May 2017 10:22

This is what I did.

I'm using the Month & Day to grab the particular line, using tokens and delims, grab my wnated search string. Ill keep looping through until it find its with a max time of 5 minutes..Each loop waiting a minute.

Code: Select all

:LOOP
FOR /f "tokens=13 delims=<" %%A IN ('findstr /C:"%MONTH% %DAY%" test.txt') DO SET RESULTS=%%A

SET CHECK=Server started in RUNNING mode^>
IF "%RESULTS%"=="%CHECK% " GOTO :EOF

TIMEOUT /T 60
GOTO LOOP

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: findstr help - Dependant search strings...

#3 Post by SIMMS7400 » 01 May 2017 13:02

Hmm, this doesn't work. As it will find the first %MONTH% %DAY% value that matches and not cycle through all lines containing %MONTH% %DAY% checking for the string.

SIMMS7400
Posts: 539
Joined: 07 Jan 2016 07:47

Re: findstr help - Dependant search strings...

#4 Post by SIMMS7400 » 01 May 2017 14:47

Hi There -

I've been able to delete the log file prior to checking it so only the newest content is written to it on start up:

Code: Select all

:CHK_WEBLOGIC

IF %PROC%==WebLogic (
   SET FILE=%OBIEE_LOG_PATH%AdminServer\logs\AdminServer.log
   ) ELSE (
      SET FILE=%OBIEE_LOG_PATH%bi_server1\logs\bi_server1.log
   )

IF EXIST %FILE% DEL %FILE%

:LOOP
IF %COUNT%==%MAX_RETRY% (
   ECHO %PROC% could not be confirmed as started >>%LOGFILE%
   ECHO Exiting process...>>%LOGFILE%
   SET "AE=T"& CALL :EXIT_PROTOCOL %PROC% "1"
)

SET CHECK=Server started in RUNNING mode

findstr /C:"%CHECK%" "%FILE%" && GOTO :EOF || ECHO %PROC% has not been started yet...

TIMEOUT /T 60
SET /A COUNT+=1
GOTO LOOP

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: findstr help - Dependant search strings...

#5 Post by elzooilogico » 02 May 2017 02:35

supposed you have %month% and %day% set, this should do the job

Code: Select all

set "month=may"
set "day=01"

FOR /f "tokens=2,23* delims=<>" %%A IN ('findstr /irc:"%MONTH% %DAY%.*<server.started.in.running.mode>" Admin_Server.log') DO (
  echo %%A %%B
)

Post Reply