Nested If Statement requiring less brackets?

Currently I’m doing a small script just to check the logs for a certain error message and then email out to our admin that said error had occurred. However, this mikrotik script is saying I need one less curly bracket, but it has two open ones. It’s throwing a problem with that last bracket and I have no idea why.

:if ( $lastTime = "" ) do={ 
    :set lastTime $currentTime 
    :local tempMessage            
    :set $tempMessage [/log get [ :pick $currentBuf ($currentLineCount-1)]
    :local found
    :set $found [:find $tempMessage "Down to Init"]
    :if ($found > 0) do={
        :log info "Found a thing!";
        :set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message]
        }
}

I’ts another script you found on internet?
http://forum.mikrotik.com/t/new-to-scripting-having-an-error-on-string-comparison/163665/1

Sorry yes I should have clarified that it was a script it used, I’m trying to figure out how I broke it on accident.

Where are defined lastTime, currentTime, currentBuf, currentLineCount, etc?

Why do you have to waste peoples time, it’s not even the complete script, it’s just a piece and the error could be before (or after).

Just some critical errors, without check the others.

:if ( $lastTime = "" ) do={ 
    :set lastTime $currentTime 
    :local tempMessage            
    :set $tempMessage [/log get [ :pick $currentBuf ($currentLineCount-1)]
#        ^ error, $ must not be used on global, local or set               ^ missing ]
    :local found
    :set $found [:find $tempMessage "Down to Init"]
#        ^ error, $ must not be used on global, local or set
    :if ($found > 0) do={
        :log info "Found a thing!";
        :set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message]
        }
}

I has assumed the error was about the curly brackets. I’ll post in my full code bellow. I modified this addresses code to work for what I need https://help.mikrotik.com/docs/display/ROS/Scripting+examples.

:global lastTime;

:global currentBuf [ :toarray [ /log find buffer=ospf  ] ] ;
:global currentLineCount [ :len $currentBuf ] ;
:global currentTime [ :totime [/log get [ :pick $currentBuf ($currentLineCount -1) ] time   ] ];

:global message "";
:log info "Starting";
:if ($lastTime = "") do={
    :set lastTime $currentTime;
    :local tempMessage;
    :set $tempMessage [/log get [ :pick $currentBuf ($currentLineCount-1)];
    :local found;
    :set $found [:find $tempMessage "Down to Init"];
    :if ($found > 0) do={
             :set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
    }

}
:if (!($found >0) do={
   :if ($lastTime < $currentTime ) do={
       :set lastTime $currentTime ; 
       :local tempMessage;
       :set $tempMessage [/log get [ :pick $currentBuf ($currentLineCount-1)];
       :local found;
       :set $found [:find $tempMessage "Down to Init"]
       :if ($found > 0) do={
             :set message [/log get [ :pick $currentBuf ($currentLineCount-1) ] message];
                   }
}

Don’t assume nothing, you must provide everytime full script, not a piece, or at least write that is only a piece…

The problem, on that fragment, is the missing ] as already noticed on previous post.

also on what you post is missing the ) before “do”

:if (!($found >0) do={

Thank you very much for both your time and patience, I will try to do better in the future!

and also is missing one ] on the same instruction on second “if” cycle

no one is born learned, even I can make mistakes,
and if I didn’t, I would worry…

Feel free to ask what you want on the forum.
For examples of how to write code read my snippets which have the link in my signature and see scripts from other users on the forum