Files
proxmoxscripts/bin/startup_check.sh
2026-01-21 11:03:33 +01:00

56 lines
2.0 KiB
Bash

#!/bin/bash
# Colori
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Formato colonne: ID(8) TYPE(6) ORDER(7) DELAY(7) NAME
HEADER_FMT="%-8s %-6s %-7s %-7s %-s\n"
# Funzione per modificare l'ordine
if [ "$1" != "" ] && [ "$2" != "" ]; then
VMID=$1
ORDER=$2
DELAY=${3:-0} # Default a 0 se non specificato
if [ -f "/etc/pve/qemu-server/$VMID.conf" ]; then
qm set $VMID --startup order=$ORDER,up=$DELAY
echo -e "${GREEN}Configurato startup per VM $VMID: ordine $ORDER, delay ${DELAY}s${NC}"
elif [ -f "/etc/pve/lxc/$VMID.conf" ]; then
pct set $VMID --startup order=$ORDER,up=$DELAY
echo -e "${GREEN}Configurato startup per CT $VMID: ordine $ORDER, delay ${DELAY}s${NC}"
else
echo -e "${YELLOW}Errore: VM/CT $VMID non trovato.${NC}"
fi
exit 0
fi
# Funzione per visualizzare
show_table() {
filter=$1
for conf_path in /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf; do
[ -e "$conf_path" ] || continue
vmid=$(basename "$conf_path" .conf)
[[ "$conf_path" == *"/qemu-server/"* ]] && type="VM" || type="CT"
name=$(grep -m 1 -E "^(name|hostname):" "$conf_path" | cut -d: -f2- | xargs)
startup=$(grep "startup:" "$conf_path")
if [ "$filter" == "with" ] && [ -n "$startup" ]; then
order=$(echo $startup | grep -oP 'order=\K\d+' || echo "0")
up=$(echo $startup | grep -oP 'up=\K\d+' || echo "0")
printf "$HEADER_FMT" "$vmid" "$type" "$order" "${up}s" "$name"
elif [ "$filter" == "without" ] && [ -z "$startup" ]; then
printf "$HEADER_FMT" "$vmid" "$type" "--" "--" "$name"
fi
done
}
echo -e "${GREEN}=== CONFIGURATI (Ordinati per Priorità) ===${NC}"
printf "${BLUE}$HEADER_FMT${NC}" "ID" "TYPE" "ORDER" "DELAY" "NAME"
show_table "with" | sort -k3,3n
echo -e "\n${YELLOW}=== NON CONFIGURATI (Default) ===${NC}"
printf "${BLUE}$HEADER_FMT${NC}" "ID" "TYPE" "ORDER" "DELAY" "NAME"
show_table "without" | sort -n