Re: multiple profiles
On Fri, 2021-04-16 at 17:57 -0700, Abu Rasheda via networkmanager-list wrote: > E.g. running the following command multiple times > > nmcli conn add type ethernet > > will create multiple files > > -rw-r--r--. 1 root root 270 Apr 16 20:53 ifcfg-ethernet > -rw-r--r--. 1 root root 272 Apr 16 20:54 ifcfg-ethernet-1 > > Is it possible for nmcli to see that ifcfg-ethernet already exist and > not create ifcfg-ethernet-1 > > How can I pass this message to nmcli > > Thanks Hi, The NetworkManager client tool (like nmcli, or a GUI) in general does not know which file name will be chosen. In the NetworkManager API you can see the file name (like - `nmcli -f all connection` - `nmcli connection up filename "$FILENAME"` - `nmcli connection load "$FILENAME"` but the client tool cannot pre-determine which file name will be used when adding a profile. If you care about the filename, create the file instead of using `nmcli connection add` (followed by `nmcli connection reload`) But is your problem really the filename here? It seems, when you add a new profile, it would be good to choose a name for it, and don't let nmcli automatically choose "ethernet" and "ethernet-1". Just do: nmcli connection add type ethernet con-name xxx "con-name" is an alias for "connection.id", and contrary to what one might reasonably expect, the "id" is not enforced to be unique: $ nmcli connection add type ethernet con-name xxx Connection 'xxx' (7f23f5cd-90f3-4cd8-8612-cf5d0856b130) successfully added. $ nmcli connection add type ethernet con-name xxx Warning: There is another connection with the name 'xxx'. Reference the connection by its uuid '8811722f-d662-48c5-9271-c8aa764d8f4a' Connection 'xxx' (8811722f-d662-48c5-9271-c8aa764d8f4a) successfully added. It's a good idea to ensure yourself that the connection.id is unique. That means, before you add a new profile, check the existing names in `nmcli connection` output and choose a different name. best, Thomas signature.asc Description: This is a digitally signed message part ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Output silence!
Hi, On Fri, 2021-04-16 at 17:52 -0700, Abu Rasheda via networkmanager-list wrote: > When a command is executed using nmcli, on the success a line like the > following is printed. > > Connection 'eth0-ethernet' (a24480cb-f5d6-40a6-a716-dba09ab53d07) > successfully added. > > Is it possible to not have this line go to standard out? > without using ">" operator. May some switch can be passed to nmcli No. Use shell and its redirection feature. There is nothing wrong with using shell's features to redirect and process the output. What is the problem with that? In general, nmcli should be usable from scripts, while also pleasing ot the interactive, human user. That is a conflict. If you write a script, you would not want this extra text but only get the UUID (or a failure). I guess, nmcli should get better here, and providing alternative outputs that are more consumable by scripts. But the result would be only more command line options, that all become part of the stable API... we are slow and reluctant to change (or even extend) the output of nmcli. For example, if you go full measure, you could be very strict about parsing the output and do something like: nmcli_my_add() { local x x=$(LANG=C nmcli connection add "$@") || return 1 x="$(printf "%s" "$x" | sed -n 's/^Connection '.*' (\(.\+\)) successfully aadded\.$/\1/p')" test -n "$x" || return 1 # Something is wrong, we failed to parse the output!! printf "%s\n" "$x" } UUID="$(nmcli_my_add type ethernet ...)" best, Thomas signature.asc Description: This is a digitally signed message part ___ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list