Winbatch

Print

Log Parser Script

SciptsAs always the code presented here is for instructional purposes. These scripts will most likely need to be modified to run in your environment. Also as I believe firmly in "re-usable code" you may find pieces of your scripts incorporated into mine. If so and you would like credit use the "email me" link and let me know. I'll be happy to add your name. Likewise if you use my code in a public forum please give me credit.

NOTE: You can copy and paste the code below to a text file, just change the extension to ".wbt" so it will run in Winbatch.

About This Script

now=dirscript()
move=dirwindows(1)
If fileexist("%now%WBDEI44I.DLL")==@TRUE then filemove("WBDEI44I.DLL",move,@FALSE)
If fileexist("%now%wwsop34i.DLL")==@TRUE then filemove("wwsop34i.DLL",move,@FALSE)
tm=TimeDate ( )
cur_tm1=ItemExtract(1, tm, "/")
cur_tm2=ItemExtract(2, cur_tm1, " ")
cur_tm3=ItemExtract(2, tm, "/")
cur_tm4=ItemExtract(3, tm, "/")
cur_tm5=ItemExtract(1, cur_tm4, " ")
cur_tm=strcat(cur_tm2,"_",cur_tm3,"_",cur_tm5)
AddExtender("wwsop34i.DLL")
#DefineSubRoutine PARSER(dlghandle,dlgmessage,dlgID,param4,param5)
MSG_Initialization=0
Butn_push=2
switch (dlgmessage)
case MSG_Initialization
DialogProcOptions(dlghandle, Butn_push, 1)
return(-1)
case Butn_push
switch dlgID
case 004
types="All Files|*.*|Text Files|*.txt|"
exlog=AskFileName( title, "c:\", types, "",1 )
DialogControlSet(dlghandle,3,3,exlog)
return(-2)
case 002
exit
return(-1)
case 001
subject=DialogControlGet(dlghandle,10,3)
emailid=DialogControlGet(dlghandle,5,3)
domain=DialogControlGet(dlghandle,6,3)
ExchngParsedData=DialogControlGet(dlghandle,7,3)
activate=0
astatusbar(0,title,"Please wait while the log is opened","","")
log=Fileopen(ExLog,"read")
OutPutFile=Fileopen(ExchngParsedData,"append")
num=0
ListNum=0
while 1
ListRead=fileread(log)
if ListRead=="*EOF*" then break
ListNum=ListNum+1
endwhile
fileclose(log)
astatusbar(0,title,"Looking for data stream.%@CRLF% Number of lines to search= %ListNum%",ListNum,num)
log=Fileopen(ExLog,"read")
while @true
line=Fileread(log)
if line=="*EOF*" then break
h=StrIndex(line, subject, "1", @FWDSCAN)
If h !=0
Activate=DialogControlGet(dlghandle,14,1)
if Activate==1
i=StrLen(emailid)
m=StrIndex(line, domain, h, @FWDSCAN)
n=m-i
l=StrSub (line, n, i)
if l != emailid
filewrite(OutPutFile,line)
endif
else
filewrite(OutPutFile,line)
endif
endif
num=num+1
remains=listnum-num
astatusbar(1,title,"Reading Lines in Log File - remaining= %remains%",ListNum,num)
endwhile
astatusbar(2,"","","",0)
return(-1)
case 016
logs=DialogControlGet(dlghandle,7,3)
Run("notepad.exe",logs)
return(-1)
endswitch
endswitch
return (-2)
#EndSubRoutine

title="Exchange Log Parser"

:top
MyDialogFormat=`WWWDLGED,6.1`
MyDialogCaption=strcat (title," by Chuck Arconi 2006")
MyDialogX=717
MyDialogY=081
MyDialogWidth=334
MyDialogHeight=169
MyDialogNumControls=017
MyDialogProcedure=`PARSER`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0
MyDialog001=`275,095,048,012,PUSHBUTTON,DEFAULT,"Start",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`275,113,048,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`055,033,214,012,EDITBOX,exlog,DEFAULT,DEFAULT,17,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`275,033,048,012,PUSHBUTTON,DEFAULT,"Locate log file",2,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog005=`113,107,122,012,EDITBOX,emailid,"Any_Mail_Id",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog006=`113,127,122,012,EDITBOX,domain,"@sampledomain.com",DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog007=`055,051,214,012,EDITBOX,ExchngParsedData,"c:\ExchangeParsedLog.txt",DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog008=`089,109,022,008,STATICTEXT,DEFAULT,"Email ID:",DEFAULT,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog009=`077,129,036,008,STATICTEXT,DEFAULT,"Email Domain:",DEFAULT,9,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog010=`055,015,214,012,EDITBOX,subject,DEFAULT,DEFAULT,11,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog011=`025,053,028,008,STATICTEXT,DEFAULT,"Output file:",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog012=`007,017,046,010,STATICTEXT,DEFAULT,"Text to search for:",DEFAULT,9,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog013=`057,071,212,076,GROUPBOX,DEFAULT,"Address to exclude from search",DEFAULT,13,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog014=`073,085,030,012,CHECKBOX,active,"Activate",1,14,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog015=`107,087,148,008,STATICTEXT,DEFAULT,"-->(Only use this section if you are searching by subject line)",DEFAULT,15,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog016=`275,051,048,012,PUSHBUTTON,DEFAULT,"Open Current Log",3,16,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog017=`005,153,076,010,VARYTEXT,tm,DEFAULT,DEFAULT,12,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ButtonPushed=Dialog("MyDialog")
goto top