You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
can't select a column that comes from incomplete record #7558
#get devices connected to network
export def get-devices [
device = "wlo1" #wlo1 for wifi (export default), eno1 for lan
#
#It needs nmap2json, installable (ubuntu at least) via
#
#sudo gem install nmap2json
] {
let ipinfo = (
if (? | where name == pnet | length) > 0 {
pnet
| where name == ($device)
| get 0
| get ips
| where type == v4
| get 0
| get addr
| str replace '(?P<nums>\d+/)' '0/'
} else {
ip -json add
| from json
| where ifname =~ $"($device)"
| select addr_info
| flatten
| find -v inet6
| flatten
| get local prefixlen
| flatten
| str collect '/'
| str replace '(?P<nums>\d+/)' '0/'
}
)
let nmap_output = (sudo nmap -oX nmap.xml -sn $ipinfo --max-parallelism 10)
let nmap_output = (nmap2json convert nmap.xml | from json | get nmaprun | get host | get address)
let this_ip = ($nmap_output | last | get addr)
let ips = ($nmap_output
| drop 1
| flatten
| where addrtype =~ ipv4
| select addr
| rename ip
)
let macs_n_names = ($nmap_output
| drop 1
| flatten
| where addrtype =~ mac
| select addr vendor
| rename mac name
| update name {|f|
if ($f.name | is-empty) {
"Unknown"
} else {
$f.name
}
}
)
let devices = ( $ips | merge $macs_n_names )
let known_devices = open ([$env.MY_ENV_VARS.linux_backup "known_devices.csv"] | path join)
let known_macs = ($known_devices | get mac | str upcase)
let known = ($devices | each {|it| any $it.mac in $known_macs} | wrap known)
let devices = ($devices | merge $known)
let aliases = (
$devices
| each {|row|
if $row.known {
$known_devices | find $row.mac | get alias
} else {
" "
}
}
| flatten
| wrap alias
)
rm nmap.xml | ignore
$devices | merge $aliases
}
that started giving me an error after 0.73 update:
let macs_n_names = ($nmap_output
| drop 1
| flatten
| where addrtype =~ mac
| select addr vendor
| rename mac name
| update name {|f|
if ($f.name | is-empty) {
"Unknown"
} else {
$f.name
}
}
)
and this is the error:
Error: nu::shell::column_not_found (link)
× Cannot find column
╭─[entry #1:1:1]
1 │ let nmap_output = (nmap2json convert nmap.xml | from json | get nmaprun | get host | get address)
· ────┬────
· ╰── value originates here
╰────
╭─[entry #6:4:1]
4 │ | where addrtype =~ mac
5 │ | select addr vendor
· ───┬──
· ╰── cannot find column 'vendor'
6 │ | rename mac name
╰────
Looking into it I tried to found the fundamental issue and I thought that it was what I posted
To investigate this, I think we need to see the table that is being piped to select addr vendor. Maybe you can save it to a temporary variable and print it.
After some exploring, the issue simplifies to what I already established. I don't why it was working before, maybe it was 0.70 the last time I tried, I don't know. I got a temporary fix like this:
let macs_n_names = (
$nmap_output
| flatten
| where addrtype =~ mac
| reject addrtype
| rename mac name
)
let macs_n_names = (
$macs_n_names
| select mac
| into df
| append (
$macs_n_names
| get name
| wrap name
| into df
)
| into nu
)
I thing it would be nice to have a builtin way to do this.
when you know the column which might be missing you could use default, e.g. [{col1: some, col2: other} {col1: blah}] | default null col2 | get col2
(tested with 0.73.0)
Activity
rgwood commentedon Dec 21, 2022
Hi, are you sure that worked until 0.72?

[{col1: some, col2: other} {col1: blah}] | select col2fails for me on 0.71 and 0.72:I wonder if this is a dataframe thing.
kurokirasama commentedon Dec 21, 2022
well, not really sure, but I have this script:
that started giving me an error after 0.73 update:
and this is the error:
Looking into it I tried to found the fundamental issue and I thought that it was what I posted
rgwood commentedon Dec 22, 2022
To investigate this, I think we need to see the table that is being piped to
select addr vendor. Maybe you can save it to a temporary variable andprintit.kurokirasama commentedon Dec 22, 2022
After some exploring, the issue simplifies to what I already established. I don't why it was working before, maybe it was 0.70 the last time I tried, I don't know. I got a temporary fix like this:
I thing it would be nice to have a builtin way to do this.
schmitzli commentedon Dec 22, 2022
when you know the column which might be missing you could use default, e.g.
[{col1: some, col2: other} {col1: blah}] | default null col2 | get col2(tested with 0.73.0)
kurokirasama commentedon Dec 22, 2022
nice!
rgwood commentedon Dec 22, 2022
If this PR goes through, eventually you'll be able to use
?col2or?.col2.