Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check files in Log directory for errors

14 views
Skip to first unread message

Odawg

unread,
Sep 13, 2005, 11:39:56 PM9/13/05
to
Hello All,

I was wondering if the the following was possible and if so, can
anyone assist:

Open each log file and search for the following text within that file
a. Error
b. Failed
c. Unsuccessful

This is what I have so far.

cmd:
@echo off

:: if an existing Log text file exist, then delete it
if exist c:\temp\templog.txt del c:\temp\templog.txt

::create the log text file to search through
dir /b c:\log > c:\temp\templog.txt

:: Set error text to look for
set error1=error
set error2=failed
set error3=unsuccessful

:: begin search loop of each log file
for /f %%a in (c:\temp\templog.txt) do call:search %%a
goto:eof

:: Can this be done in another loop to search for the error text and
:: Then pipe those filenames into the corresponding error.log file.
:: I know my syntax in SEARCH is not correct.

:: Search each log file for error text
:Search
type %1 | findstr /b /i "%error1%" >> c:\temp\%%a_%error1%.log
type %1 | findstr /b /i "%error2%" >> c:\temp\%%a_%error2%.log
type %1 | findstr /b /i "%error3%" >> c:\temp\%%a_%error3%.log


What I am trying to do is read each log file in the log directory and
see if any of those log file have any errors. If they have errors,
then, pipe the log file nameinto the corresponding error log file.

Any and all help is greatly appreciated.

Odawg

unread,
Sep 13, 2005, 11:40:22 PM9/13/05
to

Odawg

unread,
Sep 13, 2005, 11:40:26 PM9/13/05
to

Odawg

unread,
Sep 13, 2005, 11:40:29 PM9/13/05
to

Odawg

unread,
Sep 13, 2005, 11:40:33 PM9/13/05
to

Odawg

unread,
Sep 13, 2005, 11:40:36 PM9/13/05
to

foxidrive

unread,
Sep 14, 2005, 3:05:53 AM9/14/05
to
On Wed, 14 Sep 2005 03:40:36 GMT, Odawg wrote:

Try this

findstr /L /I /M "error failed unsuccessful" c:\*.log

Odawg

unread,
Sep 16, 2005, 12:37:33 AM9/16/05
to
The following code works for what I asked for thanks for all the help:

01. @echo off
02. set log=c:\log\errorlog.txt
03. for /f %%a in (templog.txt) do call:search %%a
04. goto:eof
05.
06. :Search
07. Type %1 | findstr /L /I /M "error failed" %1 >> %log%

output logfile has the following:
NortonAntivirus.log
Snagit.log
Printshop.log


Is there anyway for me to get the line or line number with the error
included in the logfile

inside the logfile to have the following:

nortonAntivirus.log
15 error updating definition file
19 failed to register

Snagit.log
22 failed to register component
24 error updating registry

Printshop.log
54 install failed.

Thanks

foxidrive

unread,
Sep 16, 2005, 3:12:52 AM9/16/05
to
On Fri, 16 Sep 2005 04:37:33 GMT, Odawg wrote:

> The following code works for what I asked for thanks for all the help:
>
> 01. @echo off
> 02. set log=c:\log\errorlog.txt
> 03. for /f %%a in (templog.txt) do call:search %%a
> 04. goto:eof
> 05.
> 06. :Search
> 07. Type %1 | findstr /L /I /M "error failed" %1 >> %log%
>
> output logfile has the following:
> NortonAntivirus.log
> Snagit.log
> Printshop.log
>
>
> Is there anyway for me to get the line or line number with the error
> included in the logfile

Try this: you can always parse the output.

findstr /L /I /N "error failed" "c:\*.log" >c:\log\errorlog.txt

Odawg

unread,
Sep 16, 2005, 6:13:55 PM9/16/05
to
One last question,

How can i space out the results in the log file?

Example of the logfile:

c:\log\EDIS_Image.log:497:05/02/2005 08:34:27 -
WARNING: Failed to disable startup group (1 of 2)
c:\log\EDIS_Image.log:498:05/02/2005 08:34:27 -
WARNING: Failed to disable startup group (2 of 2)
c:\log\EDIS_Image.log:595:05/02/2005 08:34:43 -
WARNING: Failed to disable startup group (1 of 2)
c:\log\EDIS_Image.log:596:05/02/2005 08:34:43 -
WARNING: Failed to disable startup group (2 of 2)
c:\log\EDIS_Image.log:631:05/02/2005 08:34:44 - Failed
to modify Change Password service.

To have the logfile look like the following:

c:\log\EDIS_Image.log :497 :05/02/2005 08:34:27 -
WARNING: Failed to disable startup group (1 of 2)
c:\log\EDIS_Image.log :498 :05/02/2005 08:34:27 -
WARNING: Failed to disable startup group (2 of 2)
c:\log\EDIS_Image.log :595 :05/02/2005 08:34:43 -
WARNING: Failed to disable startup group (1 of 2)
c:\log\EDIS_Image.log :596 :05/02/2005 08:34:43 -
WARNING: Failed to disable startup group (2 of 2)
c:\log\EDIS_Image.log :631 :05/02/2005 08:34:44 -
Failed to modify Change Password service.

How do I space the logfile using the " : " deliminter to look like the
above

On Fri, 16 Sep 2005 17:12:52 +1000, foxidrive

Timo Salmi

unread,
Sep 16, 2005, 10:39:22 PM9/16/05
to
Odawg wrote:
> One last question,

Promise? :-) (Of course, not really)

> How can i space out the results in the log file?
> Example of the logfile:
> c:\log\EDIS_Image.log:497:05/02/2005 08:34:27 -
> WARNING: Failed to disable startup group (1 of 2)
> c:\log\EDIS_Image.log:498:05/02/2005 08:34:27 -
> WARNING: Failed to disable startup group (2 of 2)

> To have the logfile look like the following:


> c:\log\EDIS_Image.log :497 :05/02/2005 08:34:27 -
> WARNING: Failed to disable startup group (1 of 2)
> c:\log\EDIS_Image.log :498 :05/02/2005 08:34:27 -
> WARNING: Failed to disable startup group (2 of 2)

@echo off & setlocal enableextensions enabledelayedexpansion
for /f "delims=" %%a in ('type "myfile.log"') do (
echo %%a | find "WARNING:" > nul
if !errorlevel! GTR 0 (
set r_=%%a
set a1_=!r_:~0,21!
set a2_=!r_:~21,4!
set a3_=!r_:~25,20!
echo !a1_! !a2_! !a3_! -
) else (
echo echo %%a)
)
endlocal & goto :EOF

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip

billious

unread,
Sep 17, 2005, 3:37:41 AM9/17/05
to

"Odawg" <od...@dawgoneloose.com> wrote in message
news:g6gmi15l1ge7t5q71...@4ax.com...

[snip nasty formatting caused by top-posting habit (It'll make you go
blind!)]

Since newsreaders wrap messages at odd places sometimes, it's not clear
whether your sample data is 5 lines which have been wrapped or whether the
log is actually 10 lines.

I suspect it's 5 lines because the "Failed" from the last line(-pair?)
wanders to the start of the next line when the report is reformatted.

The problem seems to be a simple matter of replacing the second and third
colons in the string with [space-colon]

So :

for /f "tokens=1-3* delims=:" %%a in (odawg.txt) do echo %%a:%%b :%%c :%%d

(all as one line)

should do the task.

HTH

...Bill

Odawg

unread,
Sep 17, 2005, 7:24:16 AM9/17/05
to
Works grerat, thanks....

Odawg

unread,
Sep 19, 2005, 10:15:51 PM9/19/05
to
okay last question,

The script works great and everything, however, in the DOS window when
the script is running, it display the following message in the DOS
windows: "..The process tried to write to a nonexistent pipe..."
What does that mean?

I think it has something to do with Line 20 but I am not sure...

Code for the script is listed below:

01. @echo off
02.
03. if exist c:\temp\filelst.txt del c:\temp\filelst.txt
04. if exist c:\temp\chkerror.txt del c:\temp\chkerror.txt
05. if exist c:\temp\results.txt del c:\temp\results.txt
06.
07. dir /b > c:\temp\filelst.txt
08.
09. set log1=c:\temp\filelst.txt
10. set log2=c:\temp\chkerror.txt
11. set log3=c:\temp\results.txt
12.
13. for /f %%a in (%log1%) do call:search %%a
14. for /f "tokens=1-3* delims=:" %%a in (%log2%) do echo %%a:%%b :%%c
15. :%%d >> %log3%
16. start %log3%
17. goto:eof
18.
19. :Search
20. Type %1 |findstr /L /I /N "error failed unsuccessful"
"c:\log\*.log" > %log2%

Odawg

unread,
Sep 19, 2005, 10:17:32 PM9/19/05
to
0 new messages