This script works by incrementing the suffix by 1 for every run, but the logic for numbers beyond 10 is not functioning correctly. It reverts back to 01 after reaching 10 instead of progressing to 11. Can anyone help me?
Cannot say if it is the cause of the issue, but at first sight this:
# Convert the new suffix to string format with proper padding
:local paddedNewSuffix;
:if ($newSuffix < 10) do={
:set paddedNewSuffix ("0" . $newSuffix);
} else={
:set paddedNewSuffix $newSuffix;
}
is “suspect”, as a side note, in other scripting languages, to pad with a leading 0, I would prepend a 0 anyway and then take only the two rightmost characters of the suffix.
The $newsuffix value may or may not become a string paddedNewSuffix without enclosing it in double quotes.
Anyway, to troubleshoot, add some :put statements and look at what the values are at the various stages.
Yes, I tried, but there is still no difference. The script still reverts back to 01 after reaching 10.
I see you are quite familiar with scripting. Can you help me? I gave remote access to one of the routers, just a router for the lab, it’s chr cloud.
For example, let’s say I have hotspot users named “ELIJAH27” and “CHARLOTTE2”.
I need “ELIJAH27” change to “ELIJAH28” and “CHARLOTTE2” change to “CHARLOTTE3” when a specific condition is met (In this case, just the prefix and limit uptime).
The first step:
Isolate Prefix and Suffix for users “ELIJAH27” or “CHARLOTTE2”.
“ELIJAH” and “CHARLOTTE” are the Prefix, and “27” and “2” are the Suffix.
As a Prefix, “ELIJAH” and “CHARLOTTE” in a name does not change.
As a Suffix, format the “27” and “2” as a numeral and ensure that the suffix is formatted as a numeral from 1 to 30.
The second step:
Use the suffix as described below:
Find hotspot users, iterate through all hotspot users and identify those with the prefix “ELIJAH” and “CHARLOTTE” and has limit-uptime of 1 second. If no user with that prefix is found, breaks out of the loop,
but when the prefixes “ELIJAH” and “CHARLOTTE” are found, update the username and password by incrementing the suffix by 1.
Yep, I got what you want to do, the doubt I have is that at a certain point in your script you are using :tonum so the variable becomes surely a number, then after the arithmetic manipulation of the number you seem like not explicitly converting the result to a string, using :tostr.
To verify/troubleshoot, if you add at each step something like:
:put $myVar
:put [:typeof $myVar]
you can verify that the variable is the right type