Jump to content
Sign in to follow this  
RestrictedUser

Write last line of log file that is updating

Recommended Posts

Hello AutoIt Scriptwriters! 👋❤️

The log file of one of Server Managers is opened and now is writing by Server Manager

Log file contents are:

2019-03-21 Error!: Syntax not found!

2019-03-21 Error! Specified language not found! 

 

How can i make a script to check the log file every 1 second, if log file writes new line, then send a MsgBox that contains last written line by Server Manager? 

Edited by Colduction

Share this post


Link to post
Share on other sites

Use FileGetSize() in a loop with sleep(1000) to get filesize.

If it changes, open the file for read, position to EOF - deltasize with filesetpos()

Fileread() and display in messagebox

 


App: Au3toCmd              UDF: _SingleScript()                             

Share this post


Link to post
Share on other sites
15 minutes ago, Exit said:

Use FileGetSize() in a loop with sleep(1000) to get filesize.

If it changes, open the file for read, position to EOF - deltasize with filesetpos()

Fileread() and display in messagebox

 

Thanks bro! 

If you write these codes, it's better😓

Share this post


Link to post
Share on other sites
7 minutes ago, Colduction said:

If you write these codes, it's better😓

Spoiler

It's really annoying to keep seeing people who, even if pointed to a Forum etiquette multiple times, keep asking for code without putting minimum effort in what they are trying to do.

Annoying and sad at the same time.

Ffs, do something and stop asking for code.

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
2 minutes ago, FrancescoDiMuro said:
  Hide contents

It's really annoying to keep seeing people who, even if pointed to a Forum etiquette multiple times, keep asking for code without pugting minimum effort in what they are trying to do.

Annoying and sad at the same time.

Ffs, do something and stop asking for code.

 

Excuse me my friend, but I'm noobie

I've just started AutoIt scripting in last week

Edited by Colduction

Share this post


Link to post
Share on other sites

@Colduction

Sure, but that's not an excuse.

If you keep asking for code without putting any effort trying to do and, most important, to understand what you are trying to do, then you'll never understand what you are doing, and you'll always need someone who spoon the code for you (even if it's not a good thing to do here).

Do something, and if you need help, then post your code here.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
39 minutes ago, FrancescoDiMuro said:

@Colduction

Sure, but that's not an excuse.

If you keep asking for code without putting any effort trying to do and, most important, to understand what you are trying to do, then you'll never understand what you are doing, and you'll always need someone who spoon the code for you (even if it's not a good thing to do here).

Do something, and if you need help, then post your code here.

Thanks bro, Okay❤️👌

Share this post


Link to post
Share on other sites

Actually you can just keep the file handle open and use readfile on it @extended will contain the characters read like so..

 

;Pseudo code
Global $g_sFile = "C:\Logfile.txt"
Global $g_hFile = FileOpen($g_sFile) ;Read Permissions
Global $g_iRetries = 60 ;Exits after 60 seconds with no new data

If $g_hFile < 0 Then
    MsgBox(0, "Error", "Can't open " & $g_sFile)
    Exit
EndIf

Global $g_sRead = ""

While $g_iRetries > 0
    $g_sRead &= FileRead($g_hFile, -1)
    ;@extended is set to the number of bytes/characters returned
    If @extended = 0 Then
        $g_iRetries -= 1
        sleep(1000)
    Else ;There is new data!!
        ConsoleWrite($g_sRead & @CRLF)
        $g_sRead = ""
        $g_iRetries = 60 ; reset wait count
    Endif   
WEnd
FileClose($g_hFile)

 

Share this post


Link to post
Share on other sites
1 hour ago, Bilgus said:

Actually you can just keep the file handle open and use readfile on it @extended will contain the characters read like so..

 

;Pseudo code
Global $g_sFile = "C:\Logfile.txt"
Global $g_hFile = FileOpen($g_sFile) ;Read Permissions
Global $g_iRetries = 60 ;Exits after 60 seconds with no new data

If $g_hFile < 0 Then
    MsgBox(0, "Error", "Can't open " & $g_sFile)
    Exit
EndIf

Global $g_sRead = ""

While $g_iRetries > 0
    $g_sRead &= FileRead($g_hFile, -1)
    ;@extended is set to the number of bytes/characters returned
    If @extended = 0 Then
        $g_iRetries -= 1
        sleep(1000)
    Else ;There is new data!!
        ConsoleWrite($g_sRead & @CRLF)
        $g_sRead = ""
        $g_iRetries = 60 ; reset wait count
    Endif   
WEnd
FileClose($g_hFile)

 

Thanks brother, Thanks🎉🍻

You've made my day🎊❤️

Share this post


Link to post
Share on other sites
On 3/11/2019 at 1:14 AM, Bilgus said:

;Pseudo code Global $g_sFile = "C:\Logfile.txt" Global $g_hFile = FileOpen($g_sFile) ;Read Permissions Global $g_iRetries = 60 ;Exits after 60 seconds with no new data If $g_hFile < 0 Then     MsgBox(0, "Error", "Can't open " & $g_sFile)     Exit EndIf Global $g_sRead = ""  While $g_iRetries > 0     $g_sRead &= FileRead($g_hFile, -1)     ;@extended is set to the number of bytes/characters returned     If @extended = 0 Then         $g_iRetries -= 1         sleep(1000)     Else ;There is new data!!         ConsoleWrite($g_sRead & @CRLF)         $g_sRead = ""         $g_iRetries = 60 ; reset wait count     Endif   WEnd FileClose($g_hFile)

excuseme, this script writes even old datas that already written by different program

can you guide me to only get new data?

Edited by Colduction

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...