On Wed, 2017-08-30 at 18:00 +0100, Colin Helliwell wrote:
On 30 August 2017 at 17:51 Thomas Haller <thaller redhat com> wrote: On Wed, 2017-08-30 at 17:17 +0100, colin helliwell ln-systems com wrote:I've not used nmcli in any of its more intricate ways, but are there some easily-parsed commands which will allow me to tell whether an Ethernet interface is up (a la 'nmcli conn up/down') AND the cable is connected ('link/carrier state')? I can grab some hints of the latter with /sys/class/net/eth0/carrier, but would prefer an approach that is harmonised through nmcli. Are there a couple of sub-commands that can be used rather than parsing the full 'nmcli dev show' output? e.g. to output a couple of specific fields.Hi, how about: LANG=C nmcli -t -m tabular -f WIRED-PROPERTIES.CARRIER device show "$DEV" ThomasThanks Thomas, that's the hints I was looking for :) I see I can do similar with GENERAL.STATE, for whether the connection has been taken up/down, and then logically And the two.
Hi, you can also request them at once: LANG=C nmcli -t -m tabular -f WIRED-PROPERTIES.CARRIER,GENERAL.STATE device show "$DEV" but that doesn't seem very nice for parsing either.
But is there a way to be assured of what the textual result will be for this one: 100/30/20, "connected"/"disconnected"/"unavailable" ? It could be a headache if NM changes one day and alters the integer/text.
In principle it should be stable, and we care very much about that. However, the current output format has some issues. - in --terse mode we also translate the output. I think that is wrong, and we might fix it in future. The future proof workaround for this is setting LANG=C - as you see, the output for state is for example "20 (unavailable)". I think that is bad, I wish we would fix it to either being only numeric or only the descriptive name. At least, in --terse mode, which is especially intended for parsing. I wish we would fix that one day, but we probably won't because it might break scripts. Especially the output of `nmcli connection show "$CON` is inconsistent about how enum values are printed (numeric, numeric + text, text, text + numeric). I wish that could be cleaned up, but we probably won't do that. Some minor adjustments though happend in the past, e.g. https://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=2e89b08343607d88cbed428726ea01f383b53ff7 - I think using the --terse most is better for scripting. We might be more willing to change the pretty-output, but pay special attention to --terse. - I don't like the current output modes much. None of the modes is very suited for parsing, because they don't escape newlines in the output. One day, I think we should escape them. Probably we'll have to add a special flag, so that the existing format doesn't change. in short: Yes, it's supposed to be stable. Thomas
Attachment:
signature.asc
Description: This is a digitally signed message part