Hi
I have a file reading loop that doesn't work exactly as expected. I have looked at it for some time and cant seem to work it out.
Anyway what I am trying to do is to read the Windows scheduled task log and report on any failed tasks. These failed tasks are represented in the log with a line that has
exit code of (n) where n is a number between 1 & 9.
Once a failed task is found, I want to loop back up thru the log file, capturing all the lines until I hit a line that starts with a " . The " indicates the task name that has failed. Once the line with the " has been found, then the script should continue reading the log.
Below is the code I have
Code:
FileRead, SchedLgU, SchedLgU.txt
; below is the code to read each line
; when a match is found read back through the file to get the previous lines until the line starting with a " is found
Loop, Parse, SchedLgU,`n, `r
{
;msgbox in file read loop `n%A_LoopField%
; skip blank lines
If A_LoopField =
Continue
; define and store all read lines as variables
Row:=A_Index
Previous:=Row-1
theline%Row% := A_LoopField
; look for string at the end of the line that is (n). and not (0). 0 indicates success
If (RegExMatch(A_LoopField, "^.*\([^0]\).$"))
{
; define the search string. when this string found at start of line, stop looking
searchSTR := Chr(34)
Loop
{
;msgbox % "Row " . Previous . "`nThis is the previous line`n" . theline%Previous%
If SubStr(theline%Previous%, 1 , 1) = searchSTR
{
;msgbox % "If statement in loop`nRow " . Previous . "`nThis is the previous line`n" . theline%Previous%
thiserrormessage .= theline%Previous% . "`n"
Break
}
Else
{
;msgbox % "Else statement in loop`nRow " . Previous . "`nThis is the previous line`n" . theline%Previous%
thiserrormessage .= theline%Previous% . "`n"
; subtract 1 for next loop
Previous--
}
}
; after getting previous line(s) , get the matched line
thiserrormessage .= A_LoopField . "`n"
}
}
msgbox "START`n%thiserrormessage%FINISH"
Below is the log file.
Code:
"01 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
01 Result: The task completed with an exit code of (1).
"11 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
11 Finished 9/20/2010 8:21:00 AM
11 More 9/20/2010 8:21:00 AM
11 MoreMore 9/20/2010 8:21:00 AM
11 Result: The task completed with an exit code of (1).
"22 TEST123 - Raise Alert for Rejected ACK for WBC.job" (perl)
22 Finished 9/20/2010 8:22:00 AM
22 Result: The task completed with an exit code of (2).
"33 TEST123 - VIF Sanity Script Alert.job" (bash.exe)
33 Finished 9/20/2010 8:23:00 AM
33 Result: The task completed with an exit code of (3).
"44 TEST123 - Copy Secure Script Bash.job" (bash.exe)
44 Finished 9/20/2010 8:24:00 AM
44Result: The task completed with an exit code of (4).
"55 TEST123 - VIF Sanity Script.job" (bash.exe)
55 Finished 9/20/2010 8:25:00 AM
55 Result: The task completed with an exit code of (5).
"66 Storage Space Monitor.job" (perl.exe)
66 Finished 9/20/2010 8:26:01 AM
66 Result: The task completed with an exit code of (6).
"77 Verify Informix Online.job" (perl.exe)
77 Finished 9/20/2010 8:27:01 AM
77 Result: The task completed with an exit code of (7).
"88 TEST123 - Monitor MQ Directories.job" (perl)
88 Finished 9/20/2010 8:28:01 AM
88 Result: The task completed with an exit code of (8).
"00 TEST123 - Monitor MQ Directories.job" (perl)
00 Finished 9/20/2010 8:28:01 AM
00 Result: The task completed with an exit code of (0).
Expected results are below
Code:
"01 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
01 Result: The task completed with an exit code of (1).
"11 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
11 Finished 9/20/2010 8:21:00 AM
11 More 9/20/2010 8:21:00 AM
11 MoreMore 9/20/2010 8:21:00 AM
11 Result: The task completed with an exit code of (1).
"22 TEST123 - Raise Alert for Rejected ACK for WBC.job" (perl)
22 Finished 9/20/2010 8:22:00 AM
22 Result: The task completed with an exit code of (2).
"33 TEST123 - VIF Sanity Script Alert.job" (bash.exe)
33 Finished 9/20/2010 8:23:00 AM
33 Result: The task completed with an exit code of (3).
"44 TEST123 - Copy Secure Script Bash.job" (bash.exe)
44 Finished 9/20/2010 8:24:00 AM
44Result: The task completed with an exit code of (4).
"55 TEST123 - VIF Sanity Script.job" (bash.exe)
55 Finished 9/20/2010 8:25:00 AM
55 Result: The task completed with an exit code of (5).
"66 Storage Space Monitor.job" (perl.exe)
66 Finished 9/20/2010 8:26:01 AM
66 Result: The task completed with an exit code of (6).
"77 Verify Informix Online.job" (perl.exe)
77 Finished 9/20/2010 8:27:01 AM
77 Result: The task completed with an exit code of (7).
"88 TEST123 - Monitor MQ Directories.job" (perl)
88 Finished 9/20/2010 8:28:01 AM
88 Result: The task completed with an exit code of (8).
What I am getting is below
Code:
"01 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
01 Result: The task completed with an exit code of (1).
11 MoreMore 9/20/2010 8:21:00 AM
11 More 9/20/2010 8:21:00 AM
11 Finished 9/20/2010 8:21:00 AM
"11 TEST123 - Move_NT_Acks_To_Darwin.job" (TEST123 - Move_NT_Acks_To_Darwin.bat)
11 Result: The task completed with an exit code of (1).
22 Finished 9/20/2010 8:22:00 AM
"22 TEST123 - Raise Alert for Rejected ACK for WBC.job" (perl)
22 Result: The task completed with an exit code of (2).
33 Finished 9/20/2010 8:23:00 AM
"33 TEST123 - VIF Sanity Script Alert.job" (bash.exe)
33 Result: The task completed with an exit code of (3).
44 Finished 9/20/2010 8:24:00 AM
"44 TEST123 - Copy Secure Script Bash.job" (bash.exe)
44Result: The task completed with an exit code of (4).
55 Finished 9/20/2010 8:25:00 AM
"55 TEST123 - VIF Sanity Script.job" (bash.exe)
55 Result: The task completed with an exit code of (5).
66 Finished 9/20/2010 8:26:01 AM
"66 Storage Space Monitor.job" (perl.exe)
66 Result: The task completed with an exit code of (6).
77 Finished 9/20/2010 8:27:01 AM
"77 Verify Informix Online.job" (perl.exe)
77 Result: The task completed with an exit code of (7).
88 Finished 9/20/2010 8:28:01 AM
"88 TEST123 - Monitor MQ Directories.job" (perl)
88 Result: The task completed with an exit code of (8).
As you can see, the actual results do not appear in the right order.
Any help in a solution, and stopping me going crazy, is greatly appreciated. Thanks