Community discussions

MikroTik App
 
User avatar
BlackRat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 97
Joined: Sat Jul 21, 2012 8:37 am

Cannot get value with console command

Sun Mar 28, 2021 4:00 pm

Strange problem.
I have dhcp-client:
[admin@MikroTik] > /ip dhcp-client print
Flags: X - disabled, I - invalid, D - dynamic
# INTERFACE USE-PEER-DNS ADD-DEFAULT-ROUTE STATUS ADDRESS
0 bridge-inet yes yes bound XXX.XXX.XXX.XXX/BB

But can't get any values by console:
[admin@MikroTik] > /ip dhcp-client get 0 address
[admin@MikroTik] > /ip dhcp-client get 0 default-route-distance
NO values listed...
If I try to use scripting everything ok:
[admin@MikroTik] > :foreach i in=[/ip dhcp-client find] do={ :put [/ip dhcp-client get $i default-route-distance];}
1
 
User avatar
BlackRat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 97
Joined: Sat Jul 21, 2012 8:37 am

Re: Cannot get value with console command

Sun Mar 28, 2021 4:00 pm

[admin@MikroTik] > /system routerboard print
routerboard: yes
board-name: hAP ac^2
model: RBD52G-5HacD2HnD
serial-number: YYYYYYYYYY
firmware-type: ipq4000L
factory-firmware: 6.44
current-firmware: 6.48.1
upgrade-firmware: 6.48.1
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11433
Joined: Thu Mar 03, 2016 10:23 pm

Re: Cannot get value with console command

Sun Mar 28, 2021 4:23 pm

Index numbers (you're using 0 in your example) are dynamic and are created when running print command. They are only valid until next print (the worst thing would be that add or remove or similar doesn't invalidate them). Which means you can't reference entries like this from scripts, you have to use find in similar manner you're doing in the working example ... you can narrow down the result list by using find where <criteria> ...
 
User avatar
BlackRat
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 97
Joined: Sat Jul 21, 2012 8:37 am

Re: Cannot get value with console command

Sun Mar 28, 2021 5:30 pm

Thank you! Now I understand... ReadTheFuckinManual - very important rule. :(

Sorry...

Who is online

Users browsing this forum: BioMax, Fogga, itvisionpk and 53 guests