Batch files

May 29, 2009 at 21:16:42
Specs: Windows XP
Hi i am new to this, i want to search a string in a log file through batch file and if it found that string, it should print 'success' otherwise 'failure' message into a txt file.


Thanks in advance


See More: Batch files

Report •


#1
May 30, 2009 at 03:06:31
@echo off
find "string" < my.log > nul
goto :%errorlevel%
:1
echo failure & goto :eof
:0
echo success


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
June 7, 2009 at 00:24:53
thanks for the answer but it is not working , it giving success even though it is a failure.
i have written the below script but still it is not working
@echo off
find "Unix" <"C:\Cognos_Data\Logs\DynamicPackaging_PCConn.log"> nul
goto :%errorlevel%
:1
echo failure >"C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
:0
echo success >"C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"

,Also i want how many times that word "unix" present in that log file ,

i.e.if that word "UNIX" in that log file present 5 times then success otherwise failure.

Thanks in advance


Report •

#3
June 7, 2009 at 10:39:02
It goes to :0 because you left out:

goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
June 8, 2009 at 02:20:15
Thanks for the reply, but i tried the below code ,its still not working,
@echo off
find "Unix" <"C:\Cognos_Data\Logs\DynamicPackaging_PCConn.log"> nul
goto :%errorlevel%
:1
echo failure & goto :eof
>"C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
:0
echo success >"C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"

Please can you help me in this logic.

i need the batch file for this code
if that word "UNIX" in that log file present 5 times then success otherwise failure.

Thank you very much


Report •

#5
June 8, 2009 at 05:45:56
Hope this does the trick:
----------------------------------------------
@echo off & cls
type nul>tempsearch.txt

::// WORD TO SEARCH FOR.
:search
find /i "unix" < "C:\Cognos_Data\Logs\DynamicPackaging_PCConn.log" >> tempsearch.txt

::// CHECK IF WORD APPEARS 5+ TIMES.
set counter=0
for /f %%A in (tempsearch.txt) do (
set line=%%A
set /a counter +=1
)

if %counter% GEQ 5 goto :GREATER_OR_EQUAL
goto :LESS

:GREATER_OR_EQUAL
echo Your search word appears more than 5 times in your document.
echo success >> "C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
echo UNIX was present %counter% times >> "C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
pause>nul
goto :EOF

:LESS
echo Your search word appears less than 5 times in your document.
echo success >> "C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
echo UNIX was present %counter% times >> "C:\Cognos_Data\Batch_Files\Incremental_batch_files\Test.txt"
pause>nul


Report •

#6
June 18, 2009 at 07:08:21
Thanks a lot its workings, But still I have one more issue, i have function PCCONN in Cognos application ,

That Command should be execute first and then the remaining logic should run

But once that Function execution is done, bat file is get finish without executing the remaining code below it.

Is there any function i can give like -f after PCCON command so that it will execute the remaing code too after this command.

e.g.

REM --------- Step 1: Use pcconnect to Redirect the datasource ---------
cd C:\Program Files\cognos\c83\webapps\utilities\PCConn
pcconn -f C:\Cognos_Data\Batch_Files\DynamicPackaging\RedirectDS.txt > "C:\Cognos_Data\Logs\DynamicPackaging_PCConn.log"

@echo off
type nul> tempsearch.txt

::// WORD TO SEARCH FOR.
:search
find /i "UNIX" < "C:\Cognos_Data\Logs\DynamicPackaging_PCConn.log" >> tempsearch.txt

::// CHECK IF WORD APPEARS 5+ TIMES.
set counter=0
for /f %%A in (tempsearch.txt) do (
set line=%%A
set /a counter +=1
)

if %counter% GEQ 5 goto :GREATER_OR_EQUAL
goto :LESS

:GREATER_OR_EQUAL

echo PCCON success >>"C:\Cognos_Data\Batch_Files\Cubemonitoring\Test.txt"
Success"
goto :EOF

:LESS
echo PCCON Failure >> "C:\Cognos_Data\Batch_Files\Cubemonitoring\Test.txt"

exit;


Report •


Ask Question