From 4c71b2c2f1ee1711bbdad2af54dbeae118750477 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 26 Mar 2026 13:45:27 +0400 Subject: [PATCH] pct-list multi ips --- bin/pct-list | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/bin/pct-list b/bin/pct-list index 66a3ca4..78f35fb 100755 --- a/bin/pct-list +++ b/bin/pct-list @@ -24,11 +24,31 @@ function lookup { function list { containers=$(lxc-ls "$CONTAINER_NAME") for id in $containers; do - info=$(lxc-info -si $id) - state=$(echo "$info" | grep '^State:') && state="${state:15}" # remove 15 leading chars hostname=$(grep -m1 hostname: "/etc/pve/lxc/$id.conf" | cut -d' ' -f2) - ip=$(echo "$info" | grep '^IP:') && ip="${ip:15}" - printf '%-5s %-30s %s %s\n' "$id" "$hostname" "$state" "$ip" + + info=$(lxc-info -si $id) + state=($(lxc-info "$id" | grep ^State:)) && state="${state[1]}" # get an array, then take the second element + + ips_input=($(echo "$info" | grep '^IP:')) || ips_input=() + ips_result=() + [[ ${#ips_input[@]} -gt 1 ]] && transform_array_to_odd_values_only ips_input ips_result + + # convert array to string joined by ',' + ips_result=$( + IFS="," + builtin echo "${ips_result[*]}" + ) + + printf '%-5s %-30s %s %s\n' "$id" "$hostname" "$state" "$ips_result" + done +} + +function transform_array_to_odd_values_only { + local -n input=$1 + local -n output=$2 + + for i in "${!input[@]}"; do + ((i % 2 == 1)) && output+=("${input[$i]}") done }