On 2020-08-01 13:55, Earl Terwilliger via users wrote:
> Hi All,
>
> I am trying to use the nmcli command to cough up
> (a highly technical term) the connected state on
> a particular network interface.
>
> According to the man page:
>
> nmcli device {status | show | set | connect | reapply
> | modify | disconnect | delete | monitor |
> wifi | lldp} [ARGUMENTS...]
> ...
>
> status
> Print status of devices.
>
> This is the default action if no command is
> specified to nmcli device.
>
> So here goes without the device:
>
> $ nmcli device status
> DEVICE TYPE STATE CONNECTION
> br0 bridge connected System br0
> virbr0 bridge connected virbr0
> eno2 ethernet connected eno2
> eno1 ethernet unavailable --
> lo loopback unmanaged --
> virbr0-nic tun unmanaged --
>
> So far so good.
>
> Now the specify as "specified" device:
>
> $ nmcli device status eno2
> Error: invalid extra argument 'eno2'.
>
> Okay, what am I doing wrong/misreading?
>
> Yes, I know I can use grep and awk. I will be
> using Raku though:
>
> $ nmcli device status | raku -ne 'for $_.lines -> $I
> { if $I.contains( "connected" & "eno2" )
> { say "connected"; last }}'
>
> connected
>
>
> Many thanks,
> -T
use show (instead of status)
Try this:
nmcli device show eno2
$ nmcli device show eno2
GENERAL.DEVICE: eno2
GENERAL.TYPE: ethernet
GENERAL.HWADDR: AC:1F:6B:62:10:07
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: eno2
GENERAL.CON-PATH:
/org/freedesktop/NetworkManager/ActiveConnection/5
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.250.135/24
IP4.GATEWAY: 192.168.250.1
IP4.ROUTE[1]: dst = 192.168.250.0/24, nh =
0.0.0.0, mt = 0
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh =
192.168.250.1, mt = 0
IP6.GATEWAY: --
That will work, but I would still need grep and awk or Raku
Thank you!