From f5ca7e8c8ced0a094ba152c0fe68146bf00cc191 Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Tue, 19 Jan 2021 00:10:23 -0500 Subject: [PATCH] vmctl: cache ip address --- vmctl/vmctl.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vmctl/vmctl.sh b/vmctl/vmctl.sh index f0cb3ce..d5a374c 100755 --- a/vmctl/vmctl.sh +++ b/vmctl/vmctl.sh @@ -121,7 +121,12 @@ function get_ip { fi assoc="$(get_ip_mac_assoc)" for addrfile in "$dir"/*.macaddr; do - printf "%s" "$assoc" | grep "$(cat "$addrfile")" | cut -d ' ' -f 1 + prefix="${addrfile%.macaddr}" + ip=$(printf "%s" "$assoc" | grep "$(cat "$addrfile")" | cut -d ' ' -f 1) + if [ "$ip" != "" ]; then + printf "%s\n" "$ip" > "$prefix.ipaddr" + fi + cat "$prefix.ipaddr" || true done }