Jump to content

tail'ing a server log file


Recommended Posts

i have found a few posts on getting auto it to tail log files and hacked together something workable (in a test platform) however when I try to implement it with the actual log file autoit just... fails >.<

hoping there is simply a flaw in my tail logic (though it works great if you are tail'ing a file that you have open with notepad :whistle:

need help.. mental help lol

Dim $Prev_Line
Dim $Curr_Line

HotKeySet("+!d", "ClearToolTip") ;Shift-Alt-d

while 1
    $aSplit = StringSplit(StringStripCR(FileRead('test.txt')), @LF)
    $Curr_Line = $aSplit[$aSplit[0]]
    if $Curr_Line <> $Prev_Line Then
    ; MsgBox(64, 'Last Line Changed:', $Curr_Line, 1)
    ; ToolTip("Curr: " & $Curr_Line & "Prev: " & $Prev_Line)
    ; ToolTip($Curr_Line)
        $Prev_Line = $Curr_Line
        
        $WhisperArray = StringRegExp($Curr_Line, "\|h\[(.*)\]\|h whispers\: (.*)",1)
        If @error == 0 Then
        ; Example line trying to regex...
        ; 6:37 PM [9:37:26] |HType:Status|h[Status]|h Link: Random Data Message Here....
            MsgBox(0, "Regex Example", $WhisperArray[0] & "Link: " & $WhisperArray[1])
        ; SoundPlay(@WindowsDir & "\media\tada.wav",1)
        EndIf
        Sleep(1000)
    EndIf
WEnd



Func ClearToolTip()
    ToolTip(""); Get rid of the tooltip on the screen
EndFunc

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

under normal circumstances i would just use perl... however with all of autoit's bells and whistles... assuming i can get a tail working there shows much promise.

also on a side note i haven't found anything funky with the log ifile itself (ie its not locked out... it can be deleted / additional lines can be saved to it via notepad....) autoit can even copy it to a new file which is why i was hoping there is just some funkiness to my tail that STINKS all puns intended lol

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

maybe?

#include <File.au3>

Dim $Prev_Line
Dim $Curr_Line
Dim $LogFile = @ScriptDir & "\test.txt"
HotKeySet("+!d", "ClearToolTip") ;Shift-Alt-d

While 1
    $Curr_Line = FileReadLine($LogFile, _FileCountLines($LogFile))
    If $Curr_Line <> $Prev_Line Then
        ; MsgBox(64, 'Last Line Changed:', $Curr_Line, 1)
        ; ToolTip("Curr: " & $Curr_Line & "Prev: " & $Prev_Line)
        ToolTip($Curr_Line)
        $Prev_Line = $Curr_Line

        $WhisperArray = StringRegExp($Curr_Line, "\|h\[(.*)\]\|h whispers\: (.*)", 1)
        If @error == 0 Then
            ; Example line trying to regex...
            ; 6:37 PM [9:37:26] |HType:Status|h[Status]|h Link: Random Data Message Here....
            MsgBox(0, "Regex Example", $WhisperArray[0] & "Link: " & $WhisperArray[1])
            ; SoundPlay(@WindowsDir & "\media\tada.wav",1)
        EndIf
    EndIf
    Sleep(200)
WEnd

Func ClearToolTip()
    ToolTip(""); Get rid of the tooltip on the screen
EndFunc   ;==>ClearToolTip

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

hi,

or if it is a huge log file (100+mb eg), and filecountlines itself takes a few secs, try my tailRW.au3 udf from my sig; lightning fast.

Best, Randall

i actually found that first though i am an autoit noob and couldn't make sense of it for the life of me... luckily i'm only having to deal with small files :whistle:

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...