# How To Detect New Log Entry - Mikrotik Script RouterOS

    This script is checking if new log entry is added to particular buffer.
    In this example we will use pppoe logs:

    /system logging action
    add name="pppoe"
    /system logging
    add action=pppoe topics=pppoe,info,!ppp,!debug

    Log buffer will look similar to this one:

    [admin@mainGW] > /log print where buffer=pppoe
    13:11:08 pppoe,info PPPoE connection established from 00:0C:42:04:4C:EE
    Now we can write a script to detect if new entry is added.

    Code:

    :global lastTime;
    :global currentBuf [ :toarray [ /log find buffer=pppoe  ] ] ;
    :global currentLineCount [ :len $currentBuf ] ;
    :global currentTime [ :totime [/log get [ :pick $currentBuf ($currentLineCount -1) ] time   ] ];
    :global message "";
    :if ( $lastTime = "" ) do={
    	:set lastTime $currentTime ;
    	:set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];

    } else={
    	:if ( $lastTime < $currentTime ) do={
    		:set lastTime $currentTime ;
    		:set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
    	}
    }
    After new entry is detected, it is saved in "message" variable, which you can use later to parse log message, for example, to get pppoe clients mac address.

    Credit: https://wiki.mikrotik.com/