Jump to content

huskies

Active Members
  • Posts

    64
  • Joined

  • Last visited

huskies's Achievements

Wayfarer

Wayfarer (2/7)

0

Reputation

  1. I don't think putty allows you to delete their log files while a session is open / so the only way this would work is if I did 1 query per session, that way I will get a fresh log file everytime. However I want to avoid doing that since that will really make the entire script that much slower.
  2. @kylomas zedna solution won't work because I will be running the SQL quries many many times, and each time I will want to extract one of the numbers. So his solution may work the second time, but becasue putty records the output in a text file in a top down fashion (so new results are appended at the end of the text file) the second time that I run the SQL query, the number that I want will not longer show up at the top of the file, it will now be at the bottom of the text file @BrewManNH What kind of ways are you thinking of? I'd love to hear some ideas. In the grand scheme of things, I trying to have Autoit queries up to 100-200 things/day, and get me those 100-200 numbers that I am interested in (each query would return a table, and I want to know the number after the date, for a specific date) and compare them to a set of another 100-200 numbers (which I will get by running another linux command) and alert me if there is a huge difference. So far I've got a proof of concept to work, but it will only read the very last line of a file.
  3. @kylomas I'm going to give a filesetpos try, it looks somewhat promising REGEX might work, it's on my list of last resorts haha @sleepydvdr Another potential solution, I will need to try to test the run time for this one since if I had a 10 MB text file, will this be speedy? @Zedna The problem is that I will be running many queries , so eventually, the data I want won't be in the begining of the file, the output would look like: if I wanted to get the second number, I will have to find it at the bottom of the text file mysql> select date, sum(visitors) folks -> FROM clpr1_f_unique_visitors LEFT JOIN dd_date ON date_fk = id -> GROUP BY date_fk; +------------+-------+ | date | folks | +------------+-------+ | 2011-10-27 | 1462 | mysql> select date, sum(visitors) folks -> FROM fgret_f_unique_visitors LEFT JOIN dd_date ON date_fk = id -> GROUP BY date_fk; +------------+-------+ | date | folks | +------------+-------+ | 2011-10-27 | 5364 | @BrewManNH I definitely need to clean up the SQL for sure, but even then, If I ran it for 50-100 different "things" my output at best will look like (putty's logging function will record everything from the command line), which means I will still have to "find" the number I'm looking for mysql> select date, sum(visitors) folks -> FROM fgret_f_unique_visitors LEFT JOIN dd_date ON date_fk = id -> GROUP BY date_fk; +------------+-------+ | date | folks | +------------+-------+ | 2011-10-27 | 1462 | mysql> select date, sum(visitors) folks -> FROM clpr1_f_unique_visitors LEFT JOIN dd_date ON date_fk = id -> GROUP BY date_fk; +------------+-------+ | date | folks | +------------+-------+ | 2011-10-27 | 5364 | . . .
  4. kylomas Thanks for your reply. My question was not "why is my code not working for that 1% of the time" I wanted to know if there was a way to read the 5th last line of a file without reading the entire file first, which my script couldn't do currently
  5. Is there a way to read a file in reverse. The only way that I know right now is to read the entire file, store it in an array and spit it out in reverse. This is not a good way because if I have a large text file this will really slow down my script. My situation, I'm trying to do a series of SQL queries using putty, after each query the output looks like this. I know the number I want is always at the 5th last line of the file, where the date is after the first pipe and the number I want is after the second pipe. again I don't want to read the entire file because if I run this code 50 times, then the putty log (a text file) will be enormous and reading the whole thing everytime is not a good idea. mysql> select date, sum(visitors) folks -> FROM clpr1_f_unique_visitors LEFT JOIN dd_date ON date_fk = id -> GROUP BY date_fk; +------------+-------+ | date | folks | +------------+-------+ | 2011-10-27 | 1462 | | 2011-10-28 | 858 | | 2011-10-29 | 725 | | 2011-10-30 | 1289 | | 2011-10-31 | 1214 | | 2011-11-01 | 1585 | | 2011-11-02 | 2555 | | 2011-11-03 | 1359 | | 2011-11-04 | 1798 | | 2011-11-05 | 1858 | | 2011-11-06 | 2837 | | 2011-11-07 | 1769 | | 2011-11-08 | 822 | +------------+-------+ 1162 rows in set (1.72 sec) mysql> My code for reading the last line of the text file is as follows and I find that it works fine 99% of the time Func ReadLog($PuttyLogpath, $Message) ;puttylog reading ;$message: the message to wait for before inputting the next command, e.g mysql> indicates that the sql is ready for the next input sleep(200) $file = fileopen($PuttyLogpath,0) ;open the text file Local $str = FileReadLine($file, -1) ; and read the very last line fileclose($file) while $str <> $Message ;the putty log will be update many times a second by putty itself and wherever there are updates in the command line, the putty log will reflect that sleep(200) $file = fileopen($PuttyLogpath,0) $str = FileReadLine($file, -1) fileclose($file) ConsoleWrite($str) WEnd if fileclose($file)=1 Then fileclose($file) endif EndFunc
  6. thanks guys, im actually on the train right now so i will give it a shot when i get home. just a little context, what I am trying to do is run a query in a database with unix, and it will take between 5 seconds to 2 minutes, when the next command line is ready that means the query is done, then I will enter my next command here are some of my custom functions, I have Putty output the results in a txt file on my desktop so I can interact with it StartPutty($Puttypath, "db5") ReadLog($PuttyLogpath, "[company@db5.prod ~]$ ") sending("./generate_mtu_data.sh apps") //this is the query that will take 2 minutes to run ReadLog($PuttyLogpath, "[company@db5.prod ~]$ ") blah blah
  7. Sometimes if this while loop have to run for more than 2 minutes,the programs gets stuck. As in my next step never gets ran. but for regular situation (around 10 seconds, it runs perfectly), so do while loops in Autoit time out after a while? $file = fileopen($PuttyLogpath,0) Local $str = FileReadLine($file, -1) while $str <> $Message sleep(200) $str = FileReadLine($file, -1) WEnd
  8. I have a javascript code that I would like to insert to the body instead of the head. Preferably at the very end of the body, how can this be done?
  9. Hi Mhz Thanks for the idea of stringregexp, i kinda took your idea and took the cheap way out, but here is my logic, I read the file with _FileReadToArray and reverse it, then I will compare every line with the function StringRegExp with the alphabet, if that line contains a letter then it is not the count I want, so far it is working pretty good. So thanks for the help $rev = "" $lines=_FileReadToArray($PuttyLogpath, $rev) ;reads the text to an array _ArrayReverse($rev) ;and then reverses it for $i = 0 to ubound($rev) - 1 $Count = $rev[$i] ;start with the last line If StringRegExp($Count, $alphabet,0) = 0 Then ; if there is a letter in this line, then it's not a count exitloop; this line doesn't have letters, so it's just a numerical count, want to keep this endif next
  10. The message box is not showing up at all, so I tried $contents = FileRead($PuttyLogpath) $value = StringRegExp($contents, '\r\n(\d*)\r\n\[companys1-ro@db17.prod ~\]$ \z', 3) Consolewrite($value) consolewrite(UBound($value)) For $i = 0 To UBound($value) -1 MsgBox(0, '', $value[$i]) Next and I got 1 for $value and 0 for Ubound($value) for every count
  11. Hi thanks for the idea, however I'm not sure if it would solve my problem. Let me explain my scope a little bit. I have to do counts on about 20-30 items per datawarehouse and so far I was able to automate putty to input the commands and have them logged in a .log file What I do is I wait for the phrase [companys1-ro@db17.prod ~] to show up in the log then I input a command that extracts a count for me, After I detect the phrase [companys1-ro@db17.prod ~] again, that means the count has been completed. The number that I want should be the second last line. I would loop it until all of the items are counted in the database. Here is a sample of the log file
  12. When I send a command to putty it gets logged, for example send("zcat /store/raw/remote/2011/05/27/*/ktraw_sdkfhgdifuygd8s7y4iudjkfghkdj* | raw-extract-messages | raw-params -p s | sort -n | uniq |wc -l") it gets sent as 3 separate lines, and to prove it i did this $file = fileopen($PuttyLogpath,0) Local $str = FileReadLine($file, (_FileCountLines($PuttyLogpath)-1)) Consolewrite($str) Would actually give me the 3rd last line: $ zcat /store/raw/remote/2011/05/27/*/ktraw_sdkfhgdi Local $str = FileReadLine($file, (_FileCountLines($puttylogpath))) gives me: fuygd8s7y4iudjkfghkdj* | raw-extract-messages | raw-params -p s | sort -n | uni and Local $str = FileReadLine($file, (_FileCountLines($puttylogpath) + 1 )) gives me:q |wc -l What I really want is the second last line and I had to do Local $str = FileReadLine($file, (_FileCountLines($puttylogpath) + 2 )) to get it, is there anyway to fix this?
  13. Hi everyone, thanks for the enthusiastic replies. 1. I do have the latest version of AutoIt fortunately. 2. my included code looks aweful because this is just a feasibility test . 3. To address the fileopen issue, here is my code $file = fileopen("C:\Users\Robert\Desktop\putty.log",0) Local $str = FileReadLine($file, -1) and actually got something. So I guess it was just a visibily issue, I assumed that because I can't see it then it's not there. 4. I did a test and filereadline was able to read as the file is getting updated without the need to fileclose. So my question is can I just use fileopen and Filereadline or is it better practice to use _FileReadToArray($path,$content)
  14. Hi I have an easy yet complicated question that's been plaguing me. A little background on the info, I'm trying to automate some putty commands in our datawarehouse. After some reading on the forums, I found that putty has a log function so I decided to use that as a way to control putty Putty can log everything from the cmd into txt file, so when the txt file says "login as:" I want to send in my username etc I tried Fileopen forthe log file but failed, and according to some posts, fileopen is troublesome with windows 7. So I tried $file = ShellExecute($file) msgbox (1,"1", FileReadLine ($file,-1)) and got nothing, Another post suggested using _FileReadToArray()because it doesn't lock the file that you opened. But what I need to do with _FileReadToArray($path,$content) is just read the LAST line of the file, and there were no documentation that described how to do that. Can someone help me out with this please? Also I heard that using plink may potentially solve this problem, but I would really like to use this method, since I need to read some of the actual data from the log file as well.
  15. that is a way, but it's not a 'sure' way of getting it to work, what if it takes different number of tab keys for one time, then it wouldn't work. Is there a way that I can veryify if the control the tab is focusing on indeed is the control I want, for exaple, by reading the text?
×
×
  • Create New...