Community discussions

MikroTik App
 
georgechyo
just joined
Topic Author
Posts: 9
Joined: Thu Dec 20, 2012 1:56 pm

RouterOS Scripting Problem

Sat Jan 12, 2013 1:15 pm

Hello,
I have a trouble in simple script:
local peer [ip ipsec remote-peers get value-name=remote-address number=0]
:log info $peer
It should get ip address of remote peer and make a log, when i run it from the winbox or schedule, it makes a blank log, but when i run the same script from the CLI it logs well.
I noticed thet when i reload router and run script from winbox it works well, but when i flush ipsec peers and reconnect, the script does the same.
 
rdc
just joined
Posts: 10
Joined: Wed Jan 09, 2013 3:40 am

Re: RouterOS Scripting Problem

Sat Jan 12, 2013 1:43 pm

what version are you running this script?

Is the local part supposed to have : (:local)?
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: RouterOS Scripting Problem

Sat Jan 12, 2013 10:38 pm

Works for me like this.
:local peer [/ip ipsec remote-peers get 0 remote-address]
:log info "Peer 0 - $peer"
 
georgechyo
just joined
Topic Author
Posts: 9
Joined: Thu Dec 20, 2012 1:56 pm

Re: RouterOS Scripting Problem

Sat Jan 12, 2013 11:15 pm

rdc
I tried different versions, tried with :local, but result is the same.

tomaskir
doesn't worked for me :(
Result is: "Peer 0 - " when run from winbox or schedule, but works when run from CLI.
when i reload router it works, but when i flush peers and reestablish it still does the same :(
I don't understand, is it a bug or what?
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: RouterOS Scripting Problem

Sun Jan 13, 2013 12:47 am

Actually, it has to do with using 0 as the identifier.
This should work always, and will return all pears as an array $peer. I use a simply :foreach to write them out.
:local peer [/ip ipsec remote-peers get [/ip ipsec remote-peers find] remote-address]

:foreach i in $peer do={
  :log info "Peer - $i"
}
 
georgechyo
just joined
Topic Author
Posts: 9
Joined: Thu Dec 20, 2012 1:56 pm

Re: RouterOS Scripting Problem

Sun Jan 13, 2013 12:06 pm

tomaskir

Thanks for your help, but it worked when there was a single tunnel (remote peer), but with more than one peer, it generates error: "invalid internal item number", in both winbox and command line.
I think that command
[/ip ipsec remote-peers get [/ip ipsec remote-peers find ] remote-address]
doesn't return an array value.
I'm week at scripting, but i need to check which tunnels are connected :(
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: RouterOS Scripting Problem

Sun Jan 13, 2013 2:31 pm

I tested with one peer only yes. I fixed it to work with multiple peers like this:
:local idArray [/ip ipsec remote-peers find]

:foreach i in $idArray do={
  :log info [/ip ipsec remote-peers get $i remote-address]
}
 
georgechyo
just joined
Topic Author
Posts: 9
Joined: Thu Dec 20, 2012 1:56 pm

Re: RouterOS Scripting Problem

Sun Jan 13, 2013 9:52 pm

tomaskir

It works :) Thank you very much :)