animeaime wrote:
Can you give some example "haystacks"?
Heres a direct snippet of my logfile thats being read
Code:
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 04:11:28.68 %%%%%%%%%%% (from node AX25 at 12-MAR-2009 04:11:28.49)
Request 3248069, from user BBSSYST on AX25
"*** FTP transfer WPTAWWW_HOURLY_MG could not log in ***"
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 04:48:25.15 %%%%%%%%%%% (from node AW1 at 12-MAR-2009 04:48:24.85)
Request 3247479, from user SYSTEM on AW1
"%GETS_F_EVENT-EMAIL PProblem with GETS fax transmission, check SLOG:[GETS]EVENT_EMAIL_ERR_2009-03-11.LOG"
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 04:54:26.94 %%%%%%%%%%% (from node AX36 at 12-MAR-2009 04:54:26.92)
Request 3248127, from user SYSTEM on AX36
"*** Job INFOSPACE_RAD_BATCH_FTP_00_00 on queue OUT_FTP_AX23 has duplicates running ***
Investigate and escalate problem if necessary"
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 04:54:41.59 %%%%%%%%%%% (from node AX22 at 12-MAR-2009 04:54:41.58)
Request 3248132, from user BBSSYST on AX22
"*** Error during BELLTELE_SVR FTP transfer. ***"
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 06:31:29.36 %%%%%%%%%%% (from node AX16 at 12-MAR-2009 06:31:29.35)
Message from user SYSTEM on AX16
FAX_FEEDBACK, restarting after unexpected exit; restart count = 116
AX26
%%%%%%%%%%% OPCOM 12-MAR-2009 06:32:23.62 %%%%%%%%%%% (from node AX30 at 12-MAR-2009 06:32:23.61)
Request 3248251, from user BBSSYST on AX30
"*** FTP transfer WKBWTV_HOURLY_MG could not log in ***"
animeaime wrote:
Also, why not use
InStr instead (or can't you)?
I played around with using InStr() but I kept getting false positives. For example, InStr(CurrentOPCOM,"could not log in") would give me a match for anything that had the word "in" inside of it, which could end up being a boat load of things.
animeaime wrote:
Also, what are you using the RegEx for? Is it that you have a list of items and you need to see if the specific item matches one of them? If so, a
continuation block combined with a
parse loop would be cleaner code.
RegEx is for pattern matching, but I don't see any pattern to match. If you give more details, I could be of more help.
I used RegExMatch since it seemed to do what I wanted the best of all the possible ways to do it that I actually understood or was able to make work.
I just need to match certain terms from each haystack (usually the last 7 lines of the log) as it appears in the log. There indivdual names of whatever generated the OPCOM will change (ie GEOMICRO_LIGHTNING, INFOSPACE, etc) but there are certain terms I will always want to look for (FTP transfer XXXX could not log in). I need it to avoid false positives more so than anything. It would be OK to consistently miss one or 2 occurences of something if it was at the cost of avoiding even a single false positive.
Heres my full script (some of it was trimmed due to senstive data

)as of this post. Im going to play around with your suggestions of a continuation block and parsing loop and see what I can work up (thanks for the example btw ... I learn by example so it helps more than you can imagine!)
Code:
;; -------------------------- Enviroment --------------------------
Process Priority,,High
SetBatchLines -1
#NoEnv
SendMode, Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2
;; -------------------------- Enviroment --------------------------
;; -------------------------- Variables --------------------------
AX26log = %A_ScriptDir%\ax26.log
username = myusername
password = mypassword
;; -------------------------- Variables --------------------------
;; -------------------------- Launch PuTTY --------------------------
;Check for existing PuTTY window
IfWinNotExist,PuTTY
{
;Delete existing PuTTY logs
FileDelete, %AX26log%
;Run the PuTTY executable
Run, %A_ScriptDir%\PuTTYPortable.exe -load "ax26"
;Check the log file for the login prompt every 100ms
Loop {
If (RegExMatch(Tail(7,AX26log),"i)Please Sign On"))
break
Sleep, 100
}
;Send the login name
ControlSend,ahk_parent,%username%{Return},PuTTY
;Check the log file for the password prompt every 100ms
Loop {
If (RegExMatch(Tail(7,AX26log),"i)Password"))
break
Sleep, 100
}
;Send the password
ControlSend,ahk_parent,%password%{Return},PuTTY
;Wait for key buffer then activate and refresh OPCOMs
Sleep, 500
ControlSend,ahk_parent,{NumPadMult},PuTTY
Sleep, 100
ControlSend,ahk_parent,{NumLock},PuTTY
}
;; -------------------------- Launch PuTTY --------------------------
;; -------------------------- Meat and Potatoes --------------------------
;Watch the log file for OPCOMS that match this criteria
Loop {
CurrentOPCOM := Tail(7,AX26log)
If (RegExMatch(CurrentOPCOM,"i)FTP transfer.*could not log in"))
GoSub, AnswerOPCOM
else if (RegExMatch(CurrentOPCOM,"i)FTP transfer.*had a 5xx error during transfer"))
GoSub, AnswerOPCOM
else if (RegExMatch(CurrentOPCOM,"i)Error during.*FTP Transfer"))
GoSub, AnswerOPCOM
else if (RegExMatch(CurrentOPCOM,"i)Job.*on queue.*has duplicates running"))
GoSub, AnswerOPCOM
}
;Extract request code from the OPCOM, reply to it, and refresh OPCOMs
AnswerOPCOM:
FindRequest := RegExMatch(CurrentOPCOM,"Request\s+\K\d+",Request_Code)
ControlSend,ahk_parent,{NumPadsub}%Request_Code%,PuTTY
ControlSend,ahk_parent,{Return},PuTTY
ControlSend,ahk_parent,{NumLock},PuTTY
Sleep, 500
Return
;; -------------------------- Meat and Potatoes --------------------------
;Function for pulling logfile tail
Tail(k,file) ;by Laszlo
{
Loop Read, %file%
{
i := Mod(A_Index,k)
L%i% = %A_LoopReadLine%
}
L := L%i%
Loop % k-1
{
IfLess i,1, SetEnv i,%k%
i-- ; Mod does not work here
L := L%i% "`n" L
}
Return L
}