Community discussions

MikroTik App
 
User avatar
brutmus
just joined
Topic Author
Posts: 7
Joined: Wed Oct 27, 2021 8:08 pm

Unable to strip netmask from Ip address in script

Wed Nov 10, 2021 4:06 pm

Hi!

I'm using RB5009 and ROS 7.1rc6

Works fine in terminal but won't work in a script. Can someone help me or is it a bug?

Alt1
:for i from=( [:len $ipaddress] - 1) to=0 do={ 
	:if ( [:pick $ipaddress $i] = "/") do={ 
		:put [:pick $ipaddress 0 $i]
	} 
}
Alt 2
:put [:pick $ipaddress 0 [:find $ipaddress "/"]]
 
User avatar
brutmus
just joined
Topic Author
Posts: 7
Joined: Wed Oct 27, 2021 8:08 pm

Re: Unable to strip netmask from Ip address in script  [SOLVED]

Fri Nov 12, 2021 9:22 am

I had to change it to:
:global ipaddress 10.1.101.1/24;
:set ipaddress [:pick $ipaddress 0 [:find $ipaddress "/"]]
to make it work
 
msatter
Forum Guru
Forum Guru
Posts: 2912
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Unable to strip netmask from Ip address in script

Fri Nov 12, 2021 1:09 pm

The solution was to use Global as it was in the Wiki: https://wiki.mikrotik.com/wiki/Manual:S ... ip_netmask
 
User avatar
brutmus
just joined
Topic Author
Posts: 7
Joined: Wed Oct 27, 2021 8:08 pm

Re: Unable to strip netmask from Ip address in script

Fri Nov 12, 2021 2:35 pm

No, that didn't work for me, I tried the wiki example.
This line is being ignored:
:put [:pick $ipaddress 0 [:find $ipaddress "/"]]
The solution was to set the variable again
:set ipaddress [:pick $ipaddress 0 [:find $ipaddress "/"]]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Unable to strip netmask from Ip address in script

Fri Nov 12, 2021 3:51 pm

Is like you do not know scripting,
":put" simply write on terminal some text,
if you must "put" the result inside a variable, is obvious than you must use set.

And also on CORRECT way (the $ before ipaddress after set command):
:global ipaddress 10.1.101.1/24
:set $ipaddress [:pick $ipaddress 0 [:find $ipaddress "/"]]
 
User avatar
brutmus
just joined
Topic Author
Posts: 7
Joined: Wed Oct 27, 2021 8:08 pm

Re: Unable to strip netmask from Ip address in script

Fri Nov 12, 2021 4:58 pm

Thank you for pointing me in the right direction!
I'm new to this, and old, but still learning!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Unable to strip netmask from Ip address in script

Fri Nov 12, 2021 5:10 pm

The forum is here for that,
have a nice day.

Who is online

Users browsing this forum: iDaemon and 13 guests