Page 1 of 1

Script doesn't work ok. Please help me solve problem

Posted: Sat Sep 28, 2013 2:34 pm
by HaPe
Welcome,
my script:

ros code

:local ipa;
:local ip;
:foreach ip in=[/ip firewall address-list find] do={
    :put [/ppp active find address=[get $ip address]];
}

ros code

[admin@gw-13-02] /ip firewall> address-list print 
Flags: X - disabled, D - dynamic 
 #   LIST                                         ADDRESS                        
 0 D nat-188.116.15.57                            192.168.100.254

ros code

[admin@gw-13-02] /ppp active> print                  
Flags: R - radius 
 #   NAME         SERVICE CALLER-ID         ADDRESS         UPTIME   ENCODING    
 0   5555         sstp    xxxxxxxxxxxx     192.168.100.254   49m44s
The result of this script is:

ros code

/system script> run test01


[admin@
Why doesn't this script return IP, only blank line?

Re: Script doesn't work ok. Please help me solve problem

Posted: Mon Sep 30, 2013 2:15 am
by skot
If I run this:

ros code

:foreach ip in=[/ip firewall address-list find] do={
    :put [/ppp active find address=[get $ip address]];
}
It returns the error:
interrupted
           invalid value for argument address
Whereas if I save the address as a variable first, then it works.

ros code

:foreach ip in=[/ip firewall address-list find] do={
  :local add [get $ip address]
  :put [/ppp active find address=$add];
}
Dunno why...

Re: Script doesn't work ok. Please help me solve problem

Posted: Mon Sep 30, 2013 5:11 am
by Ixti
The IP address as stored in the variable also includes the CIDR notation. Try using a small code section to snip it (and thank Boretto):
:local largo [:len $yourIPvariablenamehere];
:local largo [:put ($largo-3)];
:local nomask [:pick $yourIPvariablenamehere 0 $largo];
## replace "local" below with "global" if your IP variable is meant to be global
:local yourIPvariablenamehere $nomask;

Re: Script doesn't work ok. Please help me solve problem

Posted: Mon Sep 30, 2013 7:51 am
by HaPe
Thank you.