:local a [/in wi reg get number=0 last-activity] :if ($a>=2s) do={ /system reboot }An easy way to test these things is by putting the whole thing in curly braces (necessary for :local var), adding a :put statement or two for visual output, and copy/pasting the whole thing into the terminal:
{ :local a [/in wi reg get number=0 last-activity] :put $a :if ($a>=1.5s) do={ :put "reboot" # /system reboot } }One other question, are you trying to select a specific client? (based on smallest/largest last-activity value)? Just wondering because using "number=0" will simply get the first item that was added to the list, in this case the client who has been associated the longest.
It can be eitherThe "on-event" value should be the script source itself, not a script name.
Your script is causing a never ending while loop that causes the Metal's CPU to peg out at 100%. And then five minutes later it does the same thing, adding another one. Get rid of the loop for starters. And when comparing times, you can do something like this (2s being "2 seconds", and decimals are acceptable 1.5s, 2.2s, etc):ros code
:local a [/in wi reg get number=0 last-activity] :if ($a>=2s) do={ /system reboot }An easy way to test these things is by putting the whole thing in curly braces (necessary for :local var), adding a :put statement or two for visual output, and copy/pasting the whole thing into the terminal:ros code
{ :local a [/in wi reg get number=0 last-activity] :put $a :if ($a>=1.5s) do={ :put "reboot" # /system reboot } }One other question, are you trying to select a specific client? (based on smallest/largest last-activity value)? Just wondering because using "number=0" will simply get the first item that was added to the list, in this case the client who has been associated the longest.
It can be eitherThe "on-event" value should be the script source itself, not a script name.: http://wiki.mikrotik.com/wiki/Manual:Sy ... Properties
I assume you're referring to the script itself to which I agree. I think the script will be rebooting unnecessarily too often.while(true) is generally not a good idea.
Yeah. Sorry. I mean from a general scripting/programming practice view.... "while(true)" is just a way to get into trouble...I assume you're referring to the script itself to which I agree. I think the script will be rebooting unnecessarily too often.while(true) is generally not a good idea.
One other question, are you trying to select a specific client? (based on smallest/largest last-activity value)? Just wondering because using "number=0" will simply get the first item that was added to the list, in this case the client who has been associated the longest.
i am using your second script "the testing script" and i am changing the necessary.What is the result if you paste this into the terminal?
:put [/in wi reg get number=0 last-activity]
the result:What is the result if you paste this into the terminal?
:put [/in wi reg get number=0 last-activity]
{:local a [/in wi reg get number=2 last-activity]
:put $a
:if ($a>=3s) do={
/system reboot
}}[/quote]
/log info "[LAST-ACTIVITY] START" :local a [/in wi reg get number=0 last-activity] :if ($a>=70s) do={ /log info "[LAST-ACTIVITY] $a, reboot" /system reboot } else={ /log info "[LAST-ACTIVITY] $a, OK" } /log info "[LAST-ACTIVITY] FINISH"
Thanks SKOTDid the script work after you changed the time to 70s? I wonder if this might have something to do with it. Because the returned last-activity time is in the format of: 00:00:10.000, 70s would be returned as 00:01:10.000. Interesting that if I do :put 70s, it returns 00:01:10
I would troubleshoot by logging from beginning to end of the script, to get more details and to make sure the script isn't getting hung up somewhere. Then watch the logs to see what values are returned and to see if things are working properly. Maybe try changing 70s to 00:01:10 to see if that makes any difference.
ros code
/log info "[LAST-ACTIVITY] START" :local a [/in wi reg get number=0 last-activity] :if ($a>=70s) do={ /log info "[LAST-ACTIVITY] $a, reboot" /system reboot } else={ /log info "[LAST-ACTIVITY] $a, OK" } /log info "[LAST-ACTIVITY] FINISH"
{ /log info "[LAST-ACTIVITY] START" :local a [/in wi reg get number=0 last-activity] :if ($a>=70s) do={ /log info "[LAST-ACTIVITY] $a, reboot" /system reboot } else={ /log info "[LAST-ACTIVITY] $a, OK" } /log info "[LAST-ACTIVITY] FINISH" }If you run the script in System > Script, it doesn't need the brackets.
that rhight , its workIn your example, all the OK lines should have the time value just like the reboot entry.If you run the script in the terminal with :local variables, make sure to enclose the entire script in brackets:ros code
{ /log info "[LAST-ACTIVITY] START" :local a [/in wi reg get number=0 last-activity] :if ($a>=70s) do={ /log info "[LAST-ACTIVITY] $a, reboot" /system reboot } else={ /log info "[LAST-ACTIVITY] $a, OK" } /log info "[LAST-ACTIVITY] FINISH" }If you run the script in System > Script, it doesn't need the brackets.
{
/log info "[LAST-ACTIVITY] START"
:local a [/in wi reg get number=0 last-activity]
:if ($a>=1s) do={
/log info "[LAST-ACTIVITY] $a, reboot"
/system reboot
} else={
/log info "[LAST-ACTIVITY] $a, OK"
}
/log info "[LAST-ACTIVITY] FINISH"
}
In the terminal, this is normal behavior, it will ask if you want to reboot. In a script, it will reboot without the prompt.but i try to paste the last code in new terminal And the result Ask to reboot the router