The nmcli output has the format of "OPTION_NAME: VALUE", e.g.
IP4.ROUTE[4]: dst = 192.168.43.0/24, nh = 0.0.0.0, mt = 600
IP4.DNS[1]: 192.168.43.1
802-3-ethernet.s390-options: layer2=1,portname=z-104,portno=0
802-3-ethernet.s390-subchannels: --
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdump-lib.sh | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 21271cf..333591c 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -372,6 +372,30 @@ get_hwaddr()
fi
}
+
+# Parse option value from the output of nmcli connection/device show
+#
+# The output has the format of "OPTION_NAME: VALUE", e.g.
+# IP4.ROUTE[4]: dst = 192.168.43.0/24, nh = 0.0.0.0, mt =
600
+# IP4.DNS[1]: 192.168.43.1
+# 802-3-ethernet.s390-options: layer2=1,portname=z-104,portno=0
+# 802-3-ethernet.s390-subchannels: --
+#
+# Use -F (interept patterns as fixed string) for grep.
+get_nmcli_value_by_option()
+{
+ local _nmcli_out=$1
+ local _option=$2
+
+ local val=$(grep -F $_option <<< "$_nmcli_out" | sed
"s/.*:\s*//g")
+
+ if [ "$val" = "--" ]; then
+ val=""
+ fi
+
+ echo -n "$val"
+}
+
get_ifcfg_by_device()
{
grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \
--
2.30.1