Solved

logparser batch file help

Posted on 2007-03-18
12
3,116 Views
Last Modified: 2009-07-29
I can run the below fine directly from the command line.. HOwever, if I put the same line in a batch file it gives me an error..   (Error: Syntax Error: <term2>: no valid LIKE mask)

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where text like '%System%'"

How do I get this to work?? Also I want to inlude a date like statement but it will be a variable, so how do I handle that. I dont use batch files much but for what I need here it seems like easier than a script. If I could get it to work that is!!

Thanks for any help
0
Comment
Question by:andrew_89
  • 6
  • 6
12 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18745177
To put this in a batch file you must escape the %:

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where text like '^%System^%'"

If you want a date like the current date here's one method that will work on any 2000+ machine:

@echo off

call :GETDATEPARTS "%date%"

set today=%mm%/%dd%/%yy%

echo Today's date is: %today%

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

Good Luck,
Steve
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745372
Here is the line I am trying to find:
0x00000002: The system cannot find the file specified.


I am using this:
LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where text like '^%System^%'"

It does not find the line?? This is the output

Statistics:
-----------
Elements processed: 386
Elements output:    0
Execution time:     0.02 seconds
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745377
This is the return if I run from command line:

C:\Program Files\Log Parser 2.2>LogParser.exe -i:textline  "select text  from \w
indows\tasks\schedLgU.txt where text like '%System%' "
Text
-------------------------------------------------------
        0x00000002: The system cannot find the file specified.
        0x80070002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x80070002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x00000002: The system cannot find the file specified.
        0x80070002: The system cannot find the file specified.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 30

Expert Comment

by:SteveGTR
ID: 18745383
It looks like the same thing?
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745430
When I run from a batch file this is output:(Notivce what it is seeing the as the where?? Sometihng is being interpeted incorrectly.

C:\PROGRA~1\LOGPAR~1.2>LogParser.exe -i:textline  "select text  from \windows\ta
sks\schedLgU.txt where text = '^'"

Statistics:
-----------
Elements processed: 386
Elements output:    0
Execution time:     0.00 seconds
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18745538
Try this in the batch file:

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where text like '%%System%%'"
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745549
yes thanks that is the trick... Man I have killed a couple hours on something so silly..



0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18745569
Gave me trouble also :)
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745587
one other quick question sorry. If I use a date variable , what is the correct syntax in the where staement.



Thanks for all your help
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 18745601
I'd say something like this:

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where dateField = '3/18/2007'"

Or if you want to include the dynamic current date processing:

@echo off

call :GETDATEPARTS "%date%"

set today=%mm%/%dd%/%yy%

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where dateField = '%today%'"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%
0
 
LVL 1

Author Comment

by:andrew_89
ID: 18745690
The date is returned as 03/18/2007 and of course the log is 3/18/2007... How can I get rid of the 03 and make it 3?? It will not work otherwise..
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
ID: 18745702
@echo off

call :GETDATEPARTS "%date%"

set today=%mm%/%dd%/%yy%

LogParser.exe -i:textline  "select text  from \windows\tasks\schedLgU.txt where dateField = '%today%'"

goto :EOF

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
  for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
REM if 1%mm% LSS 100 set mm=0%mm%
REM if 1%dd% LSS 100 set dd=0%dd%
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question