Notify on data rate records

Hello!

I am trying running the script “Notify on data rate records” described in https://www.mikrotik.com/testdocs/ros/2.8/appex/scripting1.php
without success.

/system script add name=“record” source={
:global tmp
:global tx
:global rx
:foreach i in [/interface find] do={
/interface monitor-traffic $i once do={
:set tx ($sent-bits-per-second/1048576)
:set rx ($received-bits-per-second/1048576)
:if ([/system scheduler get record run-count]=1) do={
:global ttx
:set ttx $tx
:global trx
:set trx $rx
}
:if ($tx>$ttx) do={
/tool e-mail send
to=example@example.com
subject=“Script message”
body=("The transmission traffic on " .
[/interface get $i name] . " got up to " . $tx . “Mbps”)
:set ttx $tx
}
:if ($rx>$trx) do={
/tool e-mail send
to=example@example.com
subject=“Script message”
body=("The receiving traffic on " .
[/interface get $i name] . " got up to " . $rx . “Mbps”)
:set trx $rx
}
}
}
}

I am using RouterOS 6.19
Anybody have any idea?

Thanks
error.jpg

The scripting syntax and variable difference between v2.8 and 6.x is why the script is failing. The first black mark is a warning. There should be an equals sign = instead of a blank space; using a space is deprecated I assume.

The red marks are errors. Copy paste this line into the terminal:

/interface monitor-traffic ether1 once do={
:put (

Then press TAB a couple times to show the list of available variables:
s1.png
This shows us that the variable names have changed, and sent-bits-per-second is now tx-bits-per-second. Start typing this new name and then hit TAB again to auto-complete it. Close the parentheses, press enter, close the curly bracket, and press enter. Then you see the ouput, something like this:
s2.png
You can also use $ but the variables need to be quoted:

/interface monitor-traffic ether1 once do={
:put ($"tx-bits-per-second")
}

So, a snippet of code that works would be something like this which loops through all interfaces and finds tx and rx kbps:

:global tx
:global rx

:foreach i in=[/interface find] do={
  /interface monitor-traffic $i once do={
    :set tx ($"tx-bits-per-second"/1024)
    :put "TX: $tx"
    :set rx ($"rx-bits-per-second"/1024)
    :put "RX: $rx"
  }
}

We could clean up the script and find more errors… but what are you trying to do?