Solved

logparser batch file help

Posted on 2007-03-18
12
3,070 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Robocopy syntax 10 109
Prevent this page from creating additional dialogs. 3 385
CMD File Runs Fine By Itself But Not As Scheduled Task 21 62
Batch File tool box 5 42
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…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now