Alpinestar Posted November 25, 2008 Share Posted November 25, 2008 Hello Im really stuck on this one (Beginner). My aim is to search a log file for a keyword like "DownloadSucceeded Succeeded" then write another log file using _Filewritelog function. The code below works a treat if Im only searching for one keyword, however if I try to adapt it to search for about nine different keywords, it generates and error. Each keyword if found will generate an additional line in the new log file. I'm sure its relating to the ElseIF statement in the loop. I'm sure its something easy to the people in the know. Just not really sure how to go about this. CODE#Include <File.au3> $newfile = FileOpen(@ScriptDir & "\4sBackup.log", 1) $File = FileOpen (@ScriptDir & "\solus.log",0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $line = FileReadLine ($SolusLog) if @error = -1 then ExitLoop If Stringinstr ($line, "DownloadSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded") ElseIf Stringinstr ($line, "DownloadFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to download Upgrade files") ElseIf Stringinstr ($line, "Applied Database Upgrade") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Database has been upgraded") ElseIf Stringinstr ($line, "Database upgrades not completed correctly") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Database has not been upgraded") ElseIf Stringinstr ($line, "InstallSucceeded Failed") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the Installation.") ElseIf Stringinstr ($line, "InstallSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade was a success!") ElseIf Stringinstr ($line, "InstallFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the installation") ElseIf Stringinstr ($line, "There are no new downloads available to you at this time") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises that there are no upgrades available") ElseIf Stringinstr ($line, "Unknown Proxy Server Info") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises Unknown Proxy Server Setting") EndIf WEnd FileClose ($SolusLog) Link to comment Share on other sites More sharing options...
martin Posted November 25, 2008 Share Posted November 25, 2008 Hello Im really stuck on this one (Beginner). My aim is to search a log file for a keyword like "DownloadSucceeded Succeeded" then write another log file using _Filewritelog function. The code below works a treat if Im only searching for one keyword, however if I try to adapt it to search for about nine different keywords, it generates and error. Each keyword if found will generate an additional line in the new log file. I'm sure its relating to the ElseIF statement in the loop. I'm sure its something easy to the people in the know. Just not really sure how to go about this. CODE#Include <File.au3> $newfile = FileOpen(@ScriptDir & "\4sBackup.log", 1) $File = FileOpen (@ScriptDir & "\solus.log",0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $line = FileReadLine ($SolusLog) if @error = -1 then ExitLoop If Stringinstr ($line, "DownloadSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded") ElseIf Stringinstr ($line, "DownloadFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to download Upgrade files") ElseIf Stringinstr ($line, "Applied Database Upgrade") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Database has been upgraded") ElseIf Stringinstr ($line, "Database upgrades not completed correctly") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Database has not been upgraded") ElseIf Stringinstr ($line, "InstallSucceeded Failed") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the Installation.") ElseIf Stringinstr ($line, "InstallSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade was a success!") ElseIf Stringinstr ($line, "InstallFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the installation") ElseIf Stringinstr ($line, "There are no new downloads available to you at this time") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises that there are no upgrades available") ElseIf Stringinstr ($line, "Unknown Proxy Server Info") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises Unknown Proxy Server Setting") EndIf WEnd FileClose ($SolusLog) Maybe it should be more like this, but not tested. expandcollapse popup#Include <File.au3> $newfile = FileOpen(@ScriptDir & "\4sBackup.log", 1) $File = FileOpen(@ScriptDir & "\solus.log", 0) If $File = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($File) If @error = -1 Then ExitLoop If StringInStr($line, "DownloadSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade files have been downloaded") ElseIf StringInStr($line, "DownloadFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to download Upgrade files") ElseIf StringInStr($line, "Applied Database Upgrade") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Database has been upgraded") ElseIf StringInStr($line, "Database upgrades not completed correctly") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Database has not been upgraded") ElseIf StringInStr($line, "InstallSucceeded Failed") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the Installation.") ElseIf StringInStr($line, "InstallSucceeded Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Success - (Solus.log) Upgrade was a success!") ElseIf StringInStr($line, "InstallFailed Succeeded") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - (Solus.log) Failed to complete the installation") ElseIf StringInStr($line, "There are no new downloads available to you at this time") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises that there are no upgrades available") ElseIf StringInStr($line, "Unknown Proxy Server Info") Then _FileWriteLog(@ScriptDir & "\4SBackup.log", "Error - Solus.log advises Unknown Proxy Server Setting") EndIf WEnd FileClose($File) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Alpinestar Posted November 25, 2008 Author Share Posted November 25, 2008 @Martin Thanks for that, the script complied and generated the log file as it should . I swear I originally had the _Filewritelog commands on a different line. Does it really make a difference regarding the tabbing/Spacing ??? Will test it tomorrow when I've got a larger log file. Thanks again for your help ! Link to comment Share on other sites More sharing options...
martin Posted November 25, 2008 Share Posted November 25, 2008 @MartinThanks for that, the script complied and generated the log file as it should . I swear I originally had the _Filewritelog commands on a different line. Does it really make a difference regarding the tabbing/Spacing ??? Will test it tomorrow when I've got a larger log file. Thanks again for your help !The tabs or spaces just make it easier to read but otherwise have no function. It was important to get the statements after the 'If/Then' conditions on their own lines.You had also used a variable $SolusLog when you should have used $File as far as I could see,Glad it helped. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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