:local num 00 ;
is completely useless the ; and the 00 if not inside quotes, because numeric 000000000000000000000000000 is 0
(add "" is useless, if "00" is added to 1, first "00" is converted on a number, and is 0 + 1 = 1 // adding "1" as string to "00" is "001")
Your script, ignoring errors, change comment on same pppoe-client each 2 seconds on this sequence:
SNA1 / SNA2 / SNA3 .... SNA99997 / SNA99998 / SNA99999
It's not clear what it's for, you didn't explain it.
This generates consecutive labels, but does not read the already existing value, to modify it.
example code
{
:local prefix "SNA"
:local numlength 7
:local zeros ""
:local final 1
:local temp ""
:for x from=0 to=($numlength - 1) do={:set final ($final * 10) ; :set zeros "0$zeros"}
:for number from=0 to=($final - 1) do={
:set temp "$zeros$number"
:put ("SNA$[:pick $temp ([:len $temp] - $numlength) [:len $temp]]")
}
}
If you can ignore the superfluos 00000, and the comment is already SNAxxxxxxxx, you can use it to increase of 1 the counter:
advanced code
/interface pppoe-client print where [set pppoe-out1 comment=("SNA$([:pick $comment 3 [:len $comment]] + 1)")]
This is what you want, if is to add 1 every time the script is launched.
If the comment do not exist or is invalid, the script set it to SNA0000001
example code
{
:local iface "pppoe-out1"
:local prefix "SNA"
:local numlength 7
:local zeros ""
:local final 1
:local temp ""
:for x from=0 to=($numlength - 1) do={:set final ($final * 10) ; :set zeros "0$zeros"}
/interface pppoe-client
:local comment [get $iface comment]
:local number ([:tonum [:pick $comment [:len $prefix] [:len $comment]]] + 1)
:set temp "$zeros$number"
set $iface comment=("SNA$[:pick $temp ([:len $temp] - $numlength) [:len $temp]]")
}