Files
sibsutis/procxmos/test.sh~
T
Павел Родионов b558aaa76d proxmos
2025-11-28 18:58:15 +07:00

48 lines
1.5 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
set -euo pipefail
set -x # optional: keep for debugging
# ------------------------------------------------------------------
# Determine the directory that contains this script (handles symlinks)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load the .env file that lives beside the script
set -a # automatically export assignments
source "${SCRIPT_DIR}/.env"
set +a
# ------------------------------------------------------------------
echo "ADDR = ${ADDR}"
echo "USERNAME = ${USERNAME}"
echo "PASSWORD = ${PASSWORD}"
# ---- login ----
login=$(curl -s -k -d "username=${USERNAME}&password=${PASSWORD}" \
"https://${ADDR}:8006/api2/json/access/ticket")
echo "=== LOGIN RESPONSE ==="
echo "$login"
echo "======================"
# Extract ticket & CSRF
TICKET=$(echo "$login" | grep -o '"ticket":"[^"]*' | cut -d'"' -f4)
CSRF=$(echo "$login" | grep -o '"CSRFPreventionToken":"[^"]*' | cut -d'"' -f4)
echo "Ticket: $TICKET"
echo "CSRF : $CSRF"
echo "-------------------"
if [[ -n "$TICKET" && -n "$CSRF" ]]; then
vmlist=$(curl -s -k -b "PVEAuthCookie=${TICKET}" \
-H "CSRFPreventionToken: ${CSRF}" \
"https://${ADDR}:8006/api2/json/cluster/resources?type=vm")
echo "=== VM LIST RAW ==="
echo "$vmlist"
echo "===================="
if command -v jq >/dev/null 2>&1; then
echo "=== VM LIST FORMATTED ==="
echo "$vmlist" | jq .
fi
else
echo "Login failed no ticket/CSRF token."
fi