jacobraccuia Posted March 8, 2010 Share Posted March 8, 2010 HelloI wish for my script to loop until the only information in notepad reads "end"-------------The script takes three lines of information each time it is ran.The notepad file may look like this124.264.32.43/2 3:20virus165.357.135.3213/3 12:50virus128.164.143.243/3 14:20trojan automatorendI want the script to loop so it takes all of the information until the only thing left is "end".I do not know how to write an expression to state this.I hope this isn't too confusing; thanks so very much! Link to comment Share on other sites More sharing options...
bogQ Posted March 8, 2010 Share Posted March 8, 2010 (edited) look in help file forFileReadLine$line = FileReadLine($file) If @error = -1 Then ExitLoop If $line = "End" Then ExitLoop Edited March 8, 2010 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 8, 2010 Author Share Posted March 8, 2010 It tells me that my Do statement has no matching Until statement, although both are definitely present. Could it have something to do with If Then statements that will exit the script if a certain condition holds true? thanks Link to comment Share on other sites More sharing options...
nf67 Posted March 8, 2010 Share Posted March 8, 2010 (edited) It tells me that my Do statement has no matching Until statement, although both are definitely present. Could it have something to do with If Then statements that will exit the script if a certain condition holds true? thanks Could you post (a part of) your script? EDIT: Not sure at all wether this works or not, takes 3 lines from a file and puts them into a variable, then writes that variable into a new file in order to demonstrate the purpose. I'm having path errors with AutoItWrapper so haven't tested it and might be missing/failing at something trivial. #Include <File.au3> $Original = @ScriptDir & "\original.txt" $New = @ScriptDir & "\new.txt" CopyTextFile() Func CopyTextFile() $NumberOfLines = _FileCountLines($Original) $Lines = ($NumberOfLines - 1) / 3 ;I assume you don't need End? For $LineNumber = 1 to $Lines Step 3 $Data1 = FileReadLine($Original, $LineNumber) $Data2 = FileReadLine($Original, $LineNumber+1) $Data3 = FileReadLine($Original, $LineNumber+2) $GroupData = $Data1 & @CRLF & $Data2 & @CRLF & $Data3 & @CRLF FileWrite($New, $GroupData) FileWrite($New, "--------") Next EndFunc Edited March 8, 2010 by nf67 Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 8, 2010 Author Share Posted March 8, 2010 (edited) I'll post the entire section. I know it's not coded very well; using tab to navigate, etc, but it works. expandcollapse popupDo Send("{f2}") Send("Security") Send("{Tab}") Send("{Tab}") Send("Host") Send("{Tab}") Send("Compromised") Send("{Tab}") ;~ Finds the first IP address and copies it into Remedy WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") Send("{up 50}") Send("{left 25}") Send("{shiftdown}") Send("{down}") Send("{left}") Send("{shiftup}") Send("^x") Send("{Delete}") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("^v") send(" - compromised machine") Send("{Tab 2}") send("{enter}") Send("{Tab 10}") Send("^v") Send("{Tab 34}") Send("compromised as of ") ;~ Continues and finds the time & date WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") Send("{shiftdown}") Send("{down}") Send("{left}") Send("{shiftup}") Send("^x") Send("{Delete}") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("^v") Send("{enter}") ;~ Continues and finds the reason why Send("event - machine is hacked and backdoored - ") WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") Send("{shiftdown}") Send("{down}") Send("{left}") Send("{shiftup}") Send("^x") Send("{Delete}") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("^v") Send("{enter}") Send("remediation - rebuild machine") Send("{enter}") Send("DHCP") Send("{Enter}") Send("{Tab 10}") Send("{Shiftdown}") Send("{left 20}") Send("{Shiftup}") Send("^c") Send("{left}") ;~ Tech Eng Network to the Group+. CHANGE BACK WHEN DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!! Send("{Tab 12}") Send("{Enter}") Send("iiii") Send("{Enter}") Send("{Tab}") Send("Sara Laughlin") ;~ "Please Disable Connection" to Activity. MouseClick ( "left", 145, 320 ) Send("{Tab}") Send("Please disable connection") Send("{Shiftdown}") Send("{Tab}") Send("{Shiftup}") Send("{Shiftdown}") Send("{Left}") Send("{Shiftup}") Send("{Tab 43}") WinActivate("Document - WordPad") Send("^v") Send(" - ") ;Runs IE and looks up the IP address & sends all of the information into Notepad. If there isn't any information, it will finish the script for you.#include <IE.au3> #include <IE.au3> $oIE = _IECreate ("http://www.dhcp.gwu.edu/cgi-bin/tech_page.cgi") WinWaitActive("IPS Tech Page - Windows Internet Explorer") Send("{Tab 24}") Send("^v") Send("{Enter}") WinWaitActive("Tech DB Search - Windows Internet Explorer") $sText = _IEBodyReadText ($oIE) ;this command searches for the words "no lease found" and if they are present, it closes IE If StringInStr($sText, "No Lease Found") Then WinClose("Tech DB Search - Windows Internet Explorer") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("{Tab}") Send("unknown") Send("{Enter}") $answer = MsgBox(4, "Attention", "Do you want to save and continue? Click No if you want to pause the script until you save.") If $answer = 7 Then Exit EndIf Send("{CTRLDOWN}") Send("{Enter}") Send("{CTRLUP}") Sleep("3") WinWaitActive("AR System User - Note") Send("{Enter}") Sleep("3") WinWaitActive("Remedy User - [Help Desk Case (Modify)]") Send("{Shiftdown}") Send("{Tab 7}") Send("{SHIFTUP}") Send("{Shiftdown}") Send("{Left 7}") Send("{SHIFTUP}") Send("^c") WinActivate("Document - WordPad") WinWaitActive("Document - WordPad") Send("^v") Send("{Enter}") Exit Endif _IELinkClickByIndex ($oIE, 0) WinWaitActive("DB Search - Windows Internet Explorer") _IELinkClickByIndex ($oIE, 0) WinWaitActive("View DB Entry - Windows Internet Explorer") Send("^a") Send("^c") WinClose("View DB Entry - Windows Internet Explorer") Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("^v") ;~ ; Copies all information and places it under DHCP Send("{Backspace 29}") Send("{up 50}") Send("{Shiftdown}") Send("{down 13}") Send("{Shiftup}") Send("{Backspace}") Send("{Delete 1}") Send("^a") Send("^c") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("^v") ; Finds MAC Address and pastes it into Remedy WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") Send("{up 50}") Send("{down 2}") Send("{right 4}") Send("{Shiftdown}") Send("{right 12}") Send("{Shiftup}") Send("^c") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("{Tab 11}") Send("^v") Send("{Shiftdown}") Send("{tab 13}") Send("{Shiftup}") ;~ ; ;Program closes with the username selected. All that is left is selecting the apropriate user, if any, and saving. WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") Send("{Backspace 45}") Send("{Delete 8}") Send("{Shiftdown}") Send("{down}") Send("{Shiftup}") Send("{left}") Send("{Backspace}") Send("{Shiftdown}") Send("{left 16}") Send("{Shiftup}") Send("^c") WinClose("Untitled - Notepad") WinWaitActive("Notepad") Send("{Right}") Send("{Enter}") WinActivate("Remedy User - [Help Desk Case (New)]") WinWaitActive("Remedy User - [Help Desk Case (New)]") Send("^v") Send("{Enter}") WinWaitActive("Remedy User - [Help Desk Case (New)]") Sleep("3") $answer = MsgBox(4, "Attention", "Do you want to save and continue? Click No if you want to pause the script until you save.") If $answer = 7 Then Exit EndIf Send("{CTRLDOWN}") Send("{Enter}") Send("{CTRLUP}") Sleep("3") WinWaitActive("AR System User - Note") Send("{Enter}") Sleep("3") WinWaitActive("Remedy User - [Help Desk Case (Modify)]") Send("{Shiftdown}") Send("{Tab 7}") Send("{SHIFTUP}") Send("{Shiftdown}") Send("{Left 7}") Send("{SHIFTUP}") Send("^c") WinActivate("Document - WordPad") WinWaitActive("Document - WordPad") Send("^v") Send("{Enter}") WinActivate("Remedy User - [Help Desk Case (Modify)]") Send("{f2}") WinWaitActive("Confirm Save Request") Send("{Tab 2}") Send("{Enter}") Until $line = FileReadLine("Untitled - Notepad") If @error = -1 Then ExitLoop If $line = "end" Then ExitLoop I hope this is understandable! This is my error: C:\Program Files\AutoIt3\Include\IE.au3 (194) : ==> "Do" statement has no matching "Until" statement.: Func _IECreate($s_Url = "about:blank", $f_tryAttach = 0, $f_visible = 1, $f_wait = 1, $f_takeFocus = 1) It seems that loops do not work with IECreate.. I tried to do a similar command with While/Wend and still had no luck Edited March 8, 2010 by jacobraccuia Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 8, 2010 Author Share Posted March 8, 2010 I apologize for an unintentional bump, but my problem has changed. It seems as if the #include <IE.au3> causes an error with any loop statement. (Do, While, etc) Said error is always: C:\Program Files\AutoIt3\Include\IE.au3 (194) : ==> "Do" statement has no matching "Until" statement.: Func _IECreate($s_Url = "about:blank", $f_tryAttach = 0, $f_visible = 1, $f_wait = 1, $f_takeFocus = 1) If I remove #inclue <IE.au3> the script runs fine. However... I need that there. thanks Link to comment Share on other sites More sharing options...
enaiman Posted March 8, 2010 Share Posted March 8, 2010 (edited) WOW - you surely created a hell of a mess of a script I haven't "mentally processed" your whole code but it looks like you use Notepad to do some read lines, select and delete selection, add some info to some "Remedy" app then go to next line (again "up"-s, "left"-s and select ...) I can see that you put alot of work into this script ... I appreciate that but, you can do it in a much easier way. I imagine you are working with a log file whose last line is an "end". Instead of opening the Notepad try to read that file in an array (every line of text is read in an array element) then work on that array. Another thing is: the "#include" statement in the middle of your code and in a Do/Until loop - that is a big NO-NO. Include statements are at the top of the script. I'll build you an example using a text file with the structure you mentioned in your first post. #include <Array.au3> #include <File.au3> #include <IE.au3> Global $log_file, $log_array Global $comp_IP, $date_time, $result $log_file = @TempDir&"\log.txt" _FileReadToArray($log_file, $log_array) ;read the file content (element [0] holds the line count) _ArrayDisplay($log_array) For $i = 1 To $log_array[0] ;next line is a test for a line matching any VALID IP address (in your example only 1 IP is valid) If StringRegExp($log_array[$i], "((25[0-5]\.|2[0-4]\d\.|1\d\d\.|[1-9]\d\.|[1-9]\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9]))",0) = 1 Then $comp_IP = $log_array[$i] ;if it matches then the current line is the IP $date_time = $log_array[$i+1] ;next line is the date/time $result = $log_array[$i+2] ;next line is the result ;Put Remedy here to do whatever work is necessary MsgBox(0, "Send these to remedy", "IP: "&$comp_IP&", date/time: "&$date_time&", result: "&$result) EndIf Next Please read about _FileReadToArray, Arrays and read attentively my comments on the script. Good luck, Edited March 8, 2010 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 8, 2010 Author Share Posted March 8, 2010 Thank you so much. I will have a look at this and see what I can do My boss sends me that information [the IP, time & date], etc, and I put it into notepad so the script can take the information from there. Link to comment Share on other sites More sharing options...
JohnOne Posted March 9, 2010 Share Posted March 9, 2010 Just for the record, a do...until loop should be like this. Do ;code Until $Blah == "Blah" with the condition being on the same line. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
enaiman Posted March 9, 2010 Share Posted March 9, 2010 If your boss is sending you that info, I'm sure that we can get it in an useful form. Is the info looking as in your example? Can you post the exact format? I'm pretty sure that we can get rid of any Notepad manipulation. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 10, 2010 Author Share Posted March 10, 2010 (edited) As of right now, I have her send me something that looks like this (in an email): 128.164.181.175 3/5 9:14 Koobface 128.164.87.212 3/6 13:45 trojan inst.exe 128.164.181.188 3/8 3:38 malicious PDF grabbing malware 128.164.214.36 3/7 22:07 malicious PDF grabbing malware 128.164.213.193 3/8 9:48 trojan 128.164.149.154 3/8 11:16 NeoSploit 128.164.157.197 3/8 10:50 NeoSploit 128.164.213.98 3/8 9:31 NeoSploit 128.164.214.112 3/8 9:45 NeoSploit end I put it into notepad and the script reads from there. Also, I have it paste the ticket number with each IP address in wordpad. [lol] I'm going to be working on your first post right now. thanks! Edited March 10, 2010 by jacobraccuia Link to comment Share on other sites More sharing options...
kaotkbliss Posted March 10, 2010 Share Posted March 10, 2010 I'm still a beginner myself, so I was going to suggest something like ... Send("{Enter}") $line = FileReadLine("Untitled - Notepad") Until $line = "end" 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 10, 2010 Author Share Posted March 10, 2010 Yes, I was able to get that to work. I used $line = FileReadLine("Untitled - Notepad", 1) While $line <> end <script> wend However, I have an if, then statement. If this statement applies, how do I get the loop to continue after the EndIF command? If the IF scenario never occurs, the loop works perfectly. Otherwise, it ends after the Exit Endif Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2010 Share Posted March 10, 2010 (edited) If the If...EndIf is in the loop then use ContinueLoop or ExitLoop (depending on what you want) instead of Exit. Edited March 10, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kaotkbliss Posted March 10, 2010 Share Posted March 10, 2010 (edited) $line = FileReadLine("Untitled - Notepad", 1) While $line <> end <script> if some condition then do this endif <script continues> wend <more script> should work.... *edit* the Exit command is to stop running and close the whole script. Edited March 10, 2010 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 10, 2010 Author Share Posted March 10, 2010 (edited) So using ContinueLoop instead of Exit fixed that problem. Thanks John! However, when "end" was the only thing in notepad, it still continued the script. I have $line = FileReadLine("Untitled - Notepad", 1) While $line <> "end" <script> wend In Notepad, it looks like this: 128.164.213.98 3/8 9:31 NeoSploit 128.164.214.112 3/8 9:45 NeoSploit end Edited March 10, 2010 by jacobraccuia Link to comment Share on other sites More sharing options...
kaotkbliss Posted March 10, 2010 Share Posted March 10, 2010 filereadline needs to be inside the loop also because it reads it once then waits for a change. since it never reads it again to make a change it will loop forever. simply $line = FileReadLine("Untitled - Notepad", 1) While $line <> "end" <script> $line = FileReadLine("Untitled - Notepad", 1) wend this way, when it reaches the bottom of the loop it checks to see if end is reached 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
JohnOne Posted March 10, 2010 Share Posted March 10, 2010 Perhaps you should try something like While 1 If $line == "end" Then Exit ;Code WEnd AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jacobraccuia Posted March 10, 2010 Author Share Posted March 10, 2010 (edited) I added the command above wend and continueloop, but it still didn't work. Adding the If - Then statement did not work either. I have: $line = FileReadLine("Untitled - Notepad", 1) While 1 $line = FileReadLine("Untitled - Notepad", 1) If $line == "end" Then Exit ;script If <this> Then <that> $line = FileReadLine("Untitled - Notepad", 1) ContinueLoop EndIF ;more script $line = FileReadLine("Untitled - Notepad", 1) wend This one doesn't work either $line = FileReadLine("Untitled - Notepad", 1) While $line <> "end" ;script If <this> Then <that> $line = FileReadLine("Untitled - Notepad", 1) ContinueLoop EndIF ;more script $line = FileReadLine("Untitled - Notepad", 1) wend Edited March 10, 2010 by jacobraccuia Link to comment Share on other sites More sharing options...
kaotkbliss Posted March 10, 2010 Share Posted March 10, 2010 I added the command above wend and continueloop, but it still didn't work.Put it just before the wend$line = FileReadLine("Untitled - Notepad", 1)While $line <> "end"<script>if condition thenstuff$line = FileReadLine("Untitled - Notepad", 1)continueloopendifwendwill only recheck for "end" when it does the if statement.--------------$line = FileReadLine("Untitled - Notepad", 1)While $line <> "end"<script>if condition thenstuffcontinueloopendif$line = FileReadLine("Untitled - Notepad", 1)wendchecks everytime script goes through loop 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! 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