Community discussions

MikroTik App
 
User avatar
quotengrote
newbie
Topic Author
Posts: 33
Joined: Sun May 16, 2021 1:20 pm

invalid internal item number

Wed Oct 05, 2022 10:35 am

Hi,

when i set a variable like:
:global xx "pppoe-out-fb"
i cant use it in this where question:
/ip/address/get [find where interface "$xx" ]
invalid internal item number
Where is the problem?

Device:
/system/resource> print 
                   uptime: 3w1d18h4m48s
                  version: 7.6beta6 (development)
               build-time: Sep/07/2022 09:06:03
         factory-software: 7.0.4
              free-memory: 799.4MiB
             total-memory: 1024.0MiB
                      cpu: ARM64
                cpu-count: 4
            cpu-frequency: 350MHz
                 cpu-load: 18%
           free-hdd-space: 481.9MiB
          total-hdd-space: 513.0MiB
  write-sect-since-reboot: 74548
         write-sect-total: 995885
               bad-blocks: 0%
        architecture-name: arm64
               board-name: RB5009UG+S+
                 platform: MikroTik
Wishes
mg
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1070
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: invalid internal item number

Wed Oct 05, 2022 7:20 pm

Two (possible) issues:
  • You are missing an equal sign...
  • Your interface may have no or more than one address...
 
User avatar
quotengrote
newbie
Topic Author
Posts: 33
Joined: Sun May 16, 2021 1:20 pm

Re: invalid internal item number

Wed Oct 05, 2022 9:11 pm

With ROS6 this Syntax works as expected.
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: invalid internal item number

Wed Oct 05, 2022 9:53 pm

I use a regualar expression to match. That is the ~ sign instead of a = .

The searched interface name has to be also unique or there will no match. If you have two PPPoE (pppoe-in pppoe-out) then matching on pppoe does not cut. You have to match on the difference and the shortest one is "in" or "out" . pppoe alone will not match and so no result.
:local xx "pppoe"; :put [typeof $xx]; :put [/ip/address/get [find interface~$xx]]
I use :local and it display the type of the variable. That is in this case a string (str), so no need to put the variable $xx in quotes.
 
User avatar
quotengrote
newbie
Topic Author
Posts: 33
Joined: Sun May 16, 2021 1:20 pm

Re: invalid internal item number

Wed Oct 05, 2022 10:08 pm

Same error on ROS7; with ROS6 it works as expected.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: invalid internal item number

Wed Oct 05, 2022 11:32 pm

Returned type is an array of a single element, get command does not accept an array, either use pick command to pick the 0 element of an array or if you are sure that there is only one element then convert array to string with :tostr command
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: invalid internal item number  [SOLVED]

Fri Oct 07, 2022 2:45 am

@quotengrote, choose your method...

All tested on v6, but I do not know any reason for wat must do not work on v7, let me know, please.

:global iface "pppoe-out-fb"
:put ([/interface pppoe-client monitor $iface once as-value]->"local-address")
# do error if interface not exist
# do not contain /xx

:global iface "pppoe-out-fb"
:put [/ip address get [:tostr [find where interface=$iface]] address]
# do error if interface not exist or if interface have multiple IPs
# contain /xx and must be removed if needed

:global iface "pppoe-out-fb"
:put [/ip address get ([find where interface=$iface]->0) address]
# do error if interface not exist or if interface have no IP
# contain /xx and must be removed if needed

# on ppp profile used, on on-up script:
:global fbIP $"local-address"
# do not contain /xx
 
User avatar
quotengrote
newbie
Topic Author
Posts: 33
Joined: Sun May 16, 2021 1:20 pm

Re: invalid internal item number

Fri Oct 07, 2022 9:58 pm

@rextended and all

Thank you very much, all of these worked for me.

Wishes
mg
 
611
newbie
Posts: 37
Joined: Wed Oct 17, 2018 10:12 am

Re: invalid internal item number

Mon May 08, 2023 8:36 pm

A follow-up as I've ran into similar issue, but the cause was not apparent from this thread.
:local interface "some-interface"
:put [/ip dhcp-client get [find interface=$interface] primary-dns]
 
Results in "invalid internal item number".
:put [/ip dhcp-client get [find interface="some-interface"] primary-dns]
 
Works well.
:local dhcpinterface "some-interface"
:put [/ip dhcp-client get [find interface=$dhcpinterface] primary-dns]
 
Works well.

Tested on ROS 7.9.

The cause of error in the particular case is name clash in between parameter name "interface" and variable name "interface", use of a variable with different name solves the issue.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: invalid internal item number

Mon May 08, 2023 8:59 pm

The cause of error ...
You broke a simple law of almost all programming languages: don't use reserved words as a variable name...
If the context has "interface" as the element name, obviously you must NOT use the same name.
That's why I wrote "iface".
 
611
newbie
Posts: 37
Joined: Wed Oct 17, 2018 10:12 am

Re: invalid internal item number

Mon May 08, 2023 11:33 pm

You broke a simple law of almost all programming languages: don't use reserved words as a variable name...
Sure. The problem is DHCP client supplies interface name to the script as variable named "interface" (unlike DHCP server that uses "bindingVariableName" variables). Had to use a proxy variable instead.

I know it's in the docs (now, when I searched them for reserved variable names), but, honestly, the clash was NOT obvious - from implementation POV I've expected variables to be substituted first, in the shell or script interpreter, before the commands are executed (thus no clash is possible - the command sees no variable names), but the commands just inherit script environment and substute variables internally (thus causing clash and this, rather cryptic, error message).

An interesting feature of this internal variable substitution is ability to use values of other properties for inline filtering:
/ip firewall address-list print where address=$comment
Will print all IPv4 firewall address list entries in which the address is the same as the comment.

This, however, seems to work for find and where only.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: invalid internal item number

Mon May 08, 2023 11:37 pm

"find" and "print"...

the correct syntax is

"find where" and "print where"...

Some complex example for what can be doed with that...
/system script job print where [:typeof $script]!="nil"
(just one example from viewtopic.php?t=195953#p1000381 )
 
611
newbie
Posts: 37
Joined: Wed Oct 17, 2018 10:12 am

Re: invalid internal item number

Tue May 09, 2023 12:47 am

the correct syntax is
"find where"
While it looks more in line with "print where" this way, both docs page on scripting and /export command use "[find property=value]" without "where". Terminal autocomplete suggests that "where" is optional for "find" too.
 
User avatar
diamuxin
Member
Member
Posts: 318
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: invalid internal item number

Wed Oct 11, 2023 1:43 am

With this script I have the same error: "invalid internal item number". It works on a hAP ac^2 and does not work on a RB4011. Both with v7.11.2.

:local output
:local filename
:local sysname  [/system identity get name]

:set filename  ($"sysname"."-"."Leases.txt")

/ip dhcp-server lease
:foreach i in=[find] do={
    :local hname      [get $i host-name]
    :local activeMAC  [get $i active-mac-address]
    :local Address    [get $i address]
    :local macAddress [get $i mac-address]
    :local Status     [get $i status]
    :local Comment    [get $i comment]
    :local iface      "undefined"
    
    /interface bridge host
    :local searchresult [find where mac-address=$activeMAC]
    :if ([:len $searchresult] > 0) do={
        :set iface [get $searchresult on-interface]
    
        :if (([:typeof $hname] = "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $Comment) . "\n")
        } 
        :if (([:typeof $hname] != "nil") && ($Status = "bound")) do={
            :set output ($output . ($Address . "\t" . $macAddress . "\t" . $Status . "\t" . $iface . "\t" . $hname) . "\n")
        }
    }
}

/file print file=$filename
:delay 2s
/file set $filename contents=$output


EDIT: I don't understand anything, but there was a host in the DHCP Lease list that made it give that error, after disabling it it is working again. I am sorry for this.
Last edited by diamuxin on Wed Oct 11, 2023 12:15 pm, edited 2 times in total.

Who is online

Users browsing this forum: diamuxin, Ellaham, qatar2022 and 23 guests