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?
-----------------------------------------------------------
:local baseUsernames ("ELIJAH", "CHARLOTTE");
:local limitUptime "00:00:01";
:foreach baseUsername in=$baseUsernames do={
# Find the user in the hotspot user list
:local userIndex [/ip hotspot user find where name~"$baseUsername"];
# Check if user was found
:if ($userIndex != "") do={
# Get the current username
:local currentUser [/ip hotspot user get $userIndex name];
# Extract the suffix from the current username
:local currentSuffix;
:if ([:len $currentUser] > [:len $baseUsername]) do={
:set currentSuffix [:pick $currentUser ([:len $baseUsername] + 1) [:len $currentUser]];
} else={
:set currentSuffix "00";
}
# Convert the suffix to a number and increment it by 1
:local newSuffix ([:tonum $currentSuffix] + 1);
# Check if the new suffix exceeds 30, if so, set it to 30
:if ($newSuffix > 30) do={
:set newSuffix 30;
}
# Convert the new suffix to string format with proper padding
:local paddedNewSuffix;
:if ($newSuffix < 10) do={
:set paddedNewSuffix ("0" . $newSuffix);
} else={
:set paddedNewSuffix $newSuffix;
}
# Set the new username with the incremented suffix
:local newUsername ($baseUsername . $paddedNewSuffix);
# Set new name
/ip hotspot user set $userIndex name=$newUsername password=$newUsername;
:log info ("User $currentUser renamed to $newUsername successfully.");
} else={
:log warning ("User $baseUsername not found.");
}
}
-----------------------------------------------------------
-----------------------------------------------------------
:local baseUsernames ("ELIJAH", "CHARLOTTE");
:local limitUptime "00:00:01";
:foreach baseUsername in=$baseUsernames do={
# Find the user in the hotspot user list
:local userIndex [/ip hotspot user find where name~"$baseUsername"];
# Check if user was found
:if ($userIndex != "") do={
# Get the current username
:local currentUser [/ip hotspot user get $userIndex name];
# Extract the suffix from the current username
:local currentSuffix;
:if ([:len $currentUser] > [:len $baseUsername]) do={
:set currentSuffix [:pick $currentUser ([:len $baseUsername] + 1) [:len $currentUser]];
} else={
:set currentSuffix "00";
}
# Convert the suffix to a number and increment it by 1
:local newSuffix ([:tonum $currentSuffix] + 1);
# Check if the new suffix exceeds 30, if so, set it to 30
:if ($newSuffix > 30) do={
:set newSuffix 30;
}
# Convert the new suffix to string format with proper padding
:local paddedNewSuffix;
:if ($newSuffix < 10) do={
:set paddedNewSuffix ("0" . $newSuffix);
} else={
:set paddedNewSuffix $newSuffix;
}
# Set the new username with the incremented suffix
:local newUsername ($baseUsername . $paddedNewSuffix);
# Set new name
/ip hotspot user set $userIndex name=$newUsername password=$newUsername;
:log info ("User $currentUser renamed to $newUsername successfully.");
} else={
:log warning ("User $baseUsername not found.");
}
}
-----------------------------------------------------------
Statistics: Posted by TLL — Mon Feb 12, 2024 9:40 am