scubasteve1281 Posted November 9, 2009 Share Posted November 9, 2009 (edited) I writing a code that will search .txt log files for a failure the report those failures to the windows event logs. My sudo code looks like this Open file (C:\Logs\@year @month @day) while open read contents if the word fail is found run system event error if not contents = fail then run system event success exit loop My code looks like this so far $SystemEventError='eventcreate /T Error /ID 1000 /L APPLICATION /SO "failed" /D "logs failed"' $SystemEventSuccess='eventcreate /T Information /ID 1001 /L APPLICATION /SO "success" /D "success"' IF FileExists ("C:\Logs\@YEAR @MON @MDAY.txt") Run FileOpen ("C:\Logs\@YEAR @MON @MDAY.txt") While ;this is were I'm lost If FileRead = fail then Run(@ComSpec & " /c " & $SystemEventError, "") If not FileRead = fail then Run(@ComSpec & " /c " & $SystemEventSuccess, "") EndIf Any help filling in the pieces of the puzzle would be much appreciated Edited November 9, 2009 by scubasteve1281 Link to comment Share on other sites More sharing options...
evilertoaster Posted November 9, 2009 Share Posted November 9, 2009 Sounds like you're looking for the StringInStr() function. Check the help file. Link to comment Share on other sites More sharing options...
GEOSoft Posted November 9, 2009 Share Posted November 9, 2009 That code is totally messed up. Start with this. $SystemEventError='eventcreate /T Error /ID 1000 /L APPLICATION /SO "failed" /D "logs failed"' $SystemEventSuccess='eventcreate /T Information /ID 1001 /L APPLICATION /SO "success" /D "success"' $sFile = "C:\Logs\" & @YEAR & @MON & @MDAY & ".txt") ;;IF FileExists ("C:\Logs\@YEAR @MON @MDAY.txt") Run FileOpen ("C:\Logs\@YEAR @MON @MDAY.txt") If FileExists($sFile) Then Local $sStr = FileRead($sFile) If StringInStr($sStr, "failed") Then ;;Do Something here and remove the MsgBox() below MsgBox(0, "Result", "Failed") Else MsgBox(0, "Result", "No Failure") EndIf EndIf Now if you want to read it line by line we have a method for that too. I'm just trying to get this fixed one stage at a time so you can understand it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
scubasteve1281 Posted November 10, 2009 Author Share Posted November 10, 2009 (edited) Thanks guys I got it to work sorta I ran into a problem with the file name. The name of the file is based on the current year,month,time.txt and is created from a cmd output and will look like this 20091109.txt I can have AUTOIT try and open the latest file based on the current system date time or I can have the the initial file spit out a generic name like log.txt and have AUTOIT rename to a current time stamp. are either of these possible and which is easier. $SystemEventError='eventcreate /T Error /ID 1000 /L APPLICATION /SO "File Integrity Checker" /D "System scan error check the system scan log file located in the C:\Log file"' $SystemEventSuccess='eventcreate /T Information /ID 999 /L APPLICATION /SO "File Integrity Checker" /D "System scan completed with no errors"' $sFile = "C:\Logs" & @YEAR & @MON & @MDAY & ".txt" If FileExists($sFile) Then Local $sStr = FileRead($sFile) If StringInStr($sStr, "fail") Then Run(@ComSpec & " /c " & $SystemEventError, "") Else Run(@ComSpec & " /c " & $SystemEventSuccess, "") EndIf EndIf Edited November 10, 2009 by scubasteve1281 Link to comment Share on other sites More sharing options...
EndFunc Posted November 10, 2009 Share Posted November 10, 2009 (edited) Thanks guys I got it to work sorta I ran into a problem with the file name. The name of the file is based on the current year,month,time.txt and is created from a cmd output and will look like this 20091109.txt I can have AUTOIT try and open the latest file based on the current system date time or I can have the the initial file spit out a generic name like log.txt and have AUTOIT rename to a current time stamp. are either of these possible and which is easier. $SystemEventError='eventcreate /T Error /ID 1000 /L APPLICATION /SO "File Integrity Checker" /D "System scan error check the system scan log file located in the C:\Log file"' $SystemEventSuccess='eventcreate /T Information /ID 999 /L APPLICATION /SO "File Integrity Checker" /D "System scan completed with no errors"' $sFile = "C:\Logs" & @YEAR & @MON & @MDAY & ".txt" If FileExists($sFile) Then Local $sStr = FileRead($sFile) If StringInStr($sStr, "fail") Then Run(@ComSpec & " /c " & $SystemEventError, "") Else Run(@ComSpec & " /c " & $SystemEventSuccess, "") EndIf EndIf If I were you, I'd use AutoIt period even to create the log. Try using _FileWriteToLog() and you can have AutoIt create the log using the date everytime you need it to. So maybe write your event info in the AutoIt log. Edited November 10, 2009 by EndFunc EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now