Files
proxmox/scripts/scan-all-containers.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

109 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
# Scan all containers across all Proxmox hosts
# Outputs: VMID, name, host, IP config, current IP, status
set -euo pipefail
# Load IP configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
HOSTS=(
"${PROXMOX_HOST_ML110:-192.168.11.10}:ml110"
"${PROXMOX_HOST_R630_01:-192.168.11.11}:r630-01"
"${PROXMOX_HOST_R630_02:-192.168.11.12}:r630-02"
)
OUTPUT_FILE="/home/intlc/projects/proxmox/CONTAINER_INVENTORY_$(date +%Y%m%d_%H%M%S).md"
CSV_FILE="/home/intlc/projects/proxmox/container_inventory_$(date +%Y%m%d_%H%M%S).csv"
TEMP_DIR=$(mktemp -d)
echo "=== Scanning All Containers Across All Hosts ==="
echo ""
# Create output files
cat > "$OUTPUT_FILE" << EOF
# Container Inventory - Complete Scan
**Generated**: $(date)
**Purpose**: Complete inventory of all containers across all Proxmox hosts
---
## All Containers
| VMID | Name | Host | Status | IP Config | Current IP | Hostname |
|------|------|------|--------|----------|------------|----------|
EOF
echo "VMID,Name,Host,Status,IP_Config,Current_IP,Hostname" > "$CSV_FILE"
for host_info in "${HOSTS[@]}"; do
IFS=: read -r ip hostname <<< "$host_info"
echo "Scanning $hostname ($ip)..."
# Get all VMIDs for this host
ssh -o ConnectTimeout=10 root@"$ip" "pct list 2>/dev/null | tail -n +2 | awk '{print \$1}'" > "$TEMP_DIR/${hostname}_vmids.txt" 2>/dev/null || continue
if [ ! -s "$TEMP_DIR/${hostname}_vmids.txt" ]; then
echo " No containers found on $hostname"
continue
fi
# Process each VMID
while read -r vmid; do
[ -z "$vmid" ] && continue
# Get container info in one SSH call
container_data=$(ssh -o ConnectTimeout=10 root@"$ip" "
name=\$(pct config $vmid 2>/dev/null | grep '^name:' | cut -d: -f2 | tr -d ' ' || echo 'unnamed')
hostname_vm=\$(pct config $vmid 2>/dev/null | grep '^hostname:' | cut -d: -f2 | tr -d ' ' || echo 'N/A')
status=\$(pct status $vmid 2>/dev/null | grep 'status:' | awk '{print \$2}' || echo 'unknown')
net_config=\$(pct config $vmid 2>/dev/null | grep '^net0:' || echo '')
ip_config='N/A'
current_ip='N/A'
if echo \"\$net_config\" | grep -q 'ip='; then
ip_config=\$(echo \"\$net_config\" | grep -oE 'ip=[^,]+' | cut -d= -f2)
if [ \"\$ip_config\" = 'dhcp' ] || [ \"\$ip_config\" = 'auto' ]; then
if [ \"\$status\" = 'running' ]; then
current_ip=\$(pct exec $vmid -- hostname -I 2>/dev/null | awk '{print \$1}' || echo 'N/A')
fi
else
current_ip=\$(echo \"\$ip_config\" | cut -d'/' -f1)
fi
fi
echo \"\$name|\$hostname_vm|\$status|\$ip_config|\$current_ip\"
" 2>/dev/null || echo "|||||")
IFS='|' read -r name hostname_vm status ip_config current_ip <<< "$container_data"
# Output to files
echo "| $vmid | $name | $hostname | $status | $ip_config | $current_ip | $hostname_vm |" >> "$OUTPUT_FILE"
echo "$vmid,\"$name\",$hostname,$status,$ip_config,$current_ip,$hostname_vm" >> "$CSV_FILE"
done < "$TEMP_DIR/${hostname}_vmids.txt"
done
# Calculate summary
dhcp_count=$(grep -c "| dhcp |" "$OUTPUT_FILE" || echo "0")
static_count=$(grep -v "| dhcp |" "$OUTPUT_FILE" | grep -v "| N/A |" | grep -c "| 192.168.11" || echo "0")
total_count=$(tail -n +12 "$OUTPUT_FILE" | grep -c "^|" || echo "0")
rm -rf "$TEMP_DIR"
echo ""
echo "=== Scan Complete ==="
echo "Total containers scanned: $total_count"
echo "Output files:"
echo " - $OUTPUT_FILE"
echo " - $CSV_FILE"
echo ""
# Summary by IP config type
echo "=== Summary by IP Configuration ==="
echo "DHCP containers: $dhcp_count"
echo "Static IP containers: $static_count"
echo "Total containers: $total_count"