From fbbb68af889b8eb8c1155a7b93a01453f3aadd5d Mon Sep 17 00:00:00 2001 From: Lethary Date: Mon, 9 Mar 2026 10:30:06 +0100 Subject: [PATCH] fix : correctif du script --- CheckStorage/check_storage.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/CheckStorage/check_storage.sh b/CheckStorage/check_storage.sh index 4ec5f1e..6a13800 100644 --- a/CheckStorage/check_storage.sh +++ b/CheckStorage/check_storage.sh @@ -1,22 +1,21 @@ #!/bin/bash limit=70 -# Mettre le lien de votre webhook Discord dans un .env WEBHOOK_URL=$(grep -E '^WEBHOOK_URL=' .env | cut -d '=' -f2-) -# Récupérer l'utilisation du disque en pourcentage -usage=$(df -h / | awk 'NR==2 {gsub(/%/,"",$5); print $5}') -# Calculer l'espace libre en pourcentage +read -r total_bytes used_bytes avail_bytes usage <<<"$(df -B1 / | awk 'NR==2 {gsub(/%/,"",$5); print $2, $3, $4, $5}')" free=$((100 - usage)) +used_gb=$(awk -v b="$used_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}') +total_gb=$(awk -v b="$total_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}') +avail_gb=$(awk -v b="$avail_bytes" 'BEGIN {printf "%.2f", b/1024/1024/1024}') -# Si l'utilisation dépasse la limite, envoyer une alerte sur Discord if [ "$usage" -ge "$limit" ]; then - msgLimit="@here\n**CHECK STOCKAGE :red_circle:**\nLimite autorisé : ${limit}% \nUtilisation actuelle: ${usage}%\nEspace restant: ${free}%\nHeure: $(date)" + msgLimit="@here\n**CHECK STOCKAGE :red_circle:**\nLimite autorisé : ${limit}%\nUtilisation actuelle: ${usage}%\nEspace restant: ${free}%\nUtilise / total: ${used_gb} GB / ${total_gb} GB\nDisponible: ${avail_gb} GB\nHeure: $(date)" curl -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json; charset=utf-8" \ -d "{\"content\":\"$msgLimit\"}" \ "$WEBHOOK_URL" - # Log de l'alerte - echo "ALERTE >> ${usage}% d'utilisation, check fait le $(date)" - echo "------------------------------------------------------------" fi +echo "Espace disponible : ${avail_gb} GB" +echo "Espace utilise / espace total : ${used_gb} GB / ${total_gb} GB" +echo "Name: ${HOSTNAME}" \ No newline at end of file