Computing.Net > Forums > Programming > Batch files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch files

Reply to Message Icon

Name: vallegowni
Date: May 29, 2009 at 21:16:42 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: May 30, 2009 at 03:06:31 Pacific
Reply:

@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


0

Response Number 2
Name: vallegowni
Date: June 7, 2009 at 00:24:53 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: June 7, 2009 at 10:39:02 Pacific
Reply:

It goes to :0 because you left out:

goto :eof


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

M2


0

Response Number 4
Name: vallegowni
Date: June 8, 2009 at 02:20:15 Pacific
Reply:

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


0

Response Number 5
Name: lee123abc
Date: June 8, 2009 at 05:45:56 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: vallegowni
Date: June 18, 2009 at 07:08:21 Pacific
Reply:

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;


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch files

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html

FTP batch file www.computing.net/answers/programming/ftp-batch-file/9027.html

batch file www.computing.net/answers/programming/batch-file/13936.html