running script problem

Hi,
the following script works fine on terminal but it’s not working on “run script button” on winbox or with scheduler. the script is used to disable/enable some userman users at certain times.

:local p; :for i from=0 to=320 do={:set p [/tool user-manager user get $i actual-profile]; :if (p=“200MBN”||p=“500MBN”||p=“1GBN”) do={[/tool user-manager user set $i disabled=no]; log info “night user enabled successfully”}};

any help..

Numbers don’t work in scripts… At least in more recent versions. If you want to loop over items, it’s best that you use foreach, with a “find” command to get all IDs.

BTW, you could also use the “enable” command instead of setting disabled to no.

so:
:local p;
/tool user-manager user
:foreach i in=[find] do={
:set p [get $i actual-profile];
:if (p=“200MBN” || p=“500MBN” || p=“1GBN”) do={
enable $i;
/log info “night user enabled successfully”;
};
};

Haven’t tested the following, had no router with user-manager at hand.

/tool user-manager user {
    :local p [find actual-profile="200MBN" || actual-profile="500MBN" || actual-profile="1GBN"];
    :if ([:len $p] > 0) do={
        enable $p;
        /log info "night user enabled successfully";
    };
};

Even this should work.

/tool user-manager user enable [find actual-profile="200MBN" || actual-profile="500MBN" || actual-profile="1GBN"]
/log info "night user enabled successfully";