Community discussions

MikroTik App
 
error216216
newbie
Topic Author
Posts: 25
Joined: Fri May 23, 2014 2:07 am

Schedule script not working for new pppoe clients

Thu Dec 04, 2014 12:31 am

Hello,
I have a script that I use to read info from PPPOE client list and send it to them via SMS, disable the account etc. And it does not work for newly added clients.
I have simplified the script and added some logging info to it for debugging, the thing is that after reboot everything works, if I add a new PPPOE client when the scheduler runs the script it halts at the :set $lunaclient [:pick [ppp secret get $i comment] 0 2]; line when it reaches that user and does not even finish the script. If i put :set $username [ppp secret get $i name]; as the first line in the for it halts at that one when it reaches the new user.

If I run the script manually it works, if I reboot it works for the new client/s.

The scheduler rule and script have all priviledges enabled.
Models tested on: 951G-2HnD, 951Ui-2HnD, 2011UiAS-2HnD
Firmware: 3.19
Ver: 6.22
/log info "Startring script";
:global i 0;
:global nrclienti [:len [/ppp secret find]];
:global username 0;
:global password 0;
:global lunaclient 0;
/log info "Finnish define variables";
:for i from=0 to=($nrclienti - 1) do={
/log info "Starting to read client $i info:";
:set $lunaclient [:pick [ppp secret get $i comment] 0 2];
:set $username [ppp secret get $i name];
:set $password [ppp secret get $i password];
/log info "Values read: lunaclient=$lunaclient username=$username password=$password"
}
/log info "End of script";
For now the solution is to reboot every time I add a new user and I hope someone can help me with another option.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Schedule script not working for new pppoe clients

Thu Dec 04, 2014 2:22 am

When setting a variable, don't use the $ in front of it. Remove these and see if it works...
:set $lunaclient [:pick [ppp secret get $i comment] 0 2];
:set $username [ppp secret get $i name];
:set $password [ppp secret get $i password];


On a practical note, you could simplify the code by using :foreach
:foreach i in=[/ppp secret find] do={
  /log info "Starting to read client $i info:";
  :local lunaclient [:pick [ppp secret get $i comment] 0 2];
  :local username [ppp secret get $i name];
  :local password [ppp secret get $i password];
  /log info "Values read: lunaclient=$lunaclient username=$username password=$password"
}
 
error216216
newbie
Topic Author
Posts: 25
Joined: Fri May 23, 2014 2:07 am

Re: Schedule script not working for new pppoe clients

Thu Dec 04, 2014 3:55 am

When setting a variable, don't use the $ in front of it. Remove these and see if it works...
:set $lunaclient [:pick [ppp secret get $i comment] 0 2];
:set $username [ppp secret get $i name];
:set $password [ppp secret get $i password];


On a practical note, you could simplify the code by using :foreach
:foreach i in=[/ppp secret find] do={
  /log info "Starting to read client $i info:";
  :local lunaclient [:pick [ppp secret get $i comment] 0 2];
  :local username [ppp secret get $i name];
  :local password [ppp secret get $i password];
  /log info "Values read: lunaclient=$lunaclient username=$username password=$password"
}
Thank you, this solved my problem not the $ it works with or without, I forgot it there because out of desperation i tried all kinds of syntax variations and just forgot about it.

It seems that when I add a new user in "/ppp secrets pr" the user is on position 30 for example but using foreach "/log info "Starting to read client $i info:";" shows it's on position 36 and by rebooting it probably puts them in order, I still can't figure out why it worked when i ran the script manually. Anyway thank you again for the help!