StorCLI - Check storage script

Ce script permet de surveiller l’état du stockage du système. Il vérifie l’utilisation des espaces disque et peut générer des alertes en cas de dépassement de seuil critique. Ce script est exécuté automatiquement via une tâche cron planifiée (actuellement les lundis et vendredis à 6h00).

Fonctionnement :

  • Analyse des partitions montées
  • Détection des taux d’utilisation élevés
  • Génération d’un rapport (et éventuellement envoi par mail)

Remarques :

  • Nécessite que les outils système (df, awk, mail, etc.) soient disponibles
  • Prévoir des chemins absolus pour une exécution via cron

Script

Script bash à render executable :

#!/bin/bash
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# Last version : V1 - 2026-03-20
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# README ═══════════════════════════════════════════════════════════════════════════════════════════
# This script inspect the health of ther server and sent a report on Monday and Friday
# The following line shall be added to the crontab -------------------------------------------------
# 00 6 * * 1,5 check_storage_server-prod-0042.sh
#━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

#=======================================
# VARIABLES DEFINITION
#=======================================
MAIL="[email protected]"
REPORT="/root/check_storage_server-prod-0042.txt"
ENCLOSURE=155

# =========================
# GENERAL INFORMATIONS
# =========================
general_info() {
{
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┃ DATE: $(date)"
echo -e "┃ HOST: $(hostname)"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"

echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┣━━━━━ GENERAL INFORMATIONS"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

echo "System: $(cat /etc/redhat-release 2>/dev/null || uname -o)"
echo "Kernel: $(uname -r)"
echo "Uptime: $(uptime -p 2>/dev/null || uptime | awk -F'up ' '{print $2}' | awk -F',' '{print $1}')"
echo -e "\n"

} > "$REPORT"
}

# =========================
# SUMMARY DISKS
# =========================
summary_disk(){
{
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┣━━━━━ DISKS SUMMARY"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

echo -e "---------------------------------------------------------------------------------"
printf "| %-12s | %-5s | %-14s | %-11s | %-8s | %-6s | %-3s |\n" "EID:Slt" "State" "Status" "Temperature" "Size" "Port" "PFC"
echo -e "---------------------------------------------------------------------------------"

for slot in {1..8}; do
/opt/MegaRAID/storcli/storcli64 /c0/e"$ENCLOSURE"/s"$slot" show all | \
awk '
/^Status =/ {status=$3}
/^[0-9]+:/ {eid_slt=$1; state=$3; size=$5" "$6}
/Drive Temperature/ {temp=$4}
/Predictive Failure Count/ {pfc=$5}
/^Port Status/ {getline; getline; port=$2}
END {
printf "| %-12s | %-5s | %-14s | %-11s | %-8s | %-6s | %-3s |\n", \
""eid_slt, state, status, temp, size, port, pfc
}'
done

echo -e "\n"
echo -e "EID:Slt = Enclosure Device ID:Slot disk"
echo -e "PFC = Predictive Failure Count"
echo -e "DHS = Dedicated Spare Drive"
echo -e "\n"

} >> "$REPORT"
}

# =========================
# ENCLOSURE INFORMATIONS
# =========================
enclosure_info(){
{
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┣━━━━━ ENCLOSURE INFORMATIONS"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
/opt/MegaRAID/storcli/storcli64 /c0/e$ENCLOSURE show | head -n13
echo -e "\n"

} >> "$REPORT"
}

# =========================
# DIKS INFORMATIONS
# =========================
disk_info(){
{
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┣━━━━━ DISKS INFORMATIONS"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
/opt/MegaRAID/storcli/storcli64 /c0/e$ENCLOSURE/sall show | head -n20
echo -e "\n"

} >> "$REPORT"
}


# =========================
# DIKS INFORMATIONS
# =========================
disk_details_info(){
{
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "┣━━━━━ DISKS INFORMATIONS DETAILS"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"

for slot in {1..8}; do
echo -e "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo -e "┣━━━━━ Slot $slot ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"
echo -e "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"
/opt/MegaRAID/storcli/storcli64 /c0/e$ENCLOSURE/s"$slot" show all
echo -e "\n"
done

} >> "$REPORT"
}


# =========================
# SEND REPORT
# =========================
send_mail() {

local BOUNDARY="====BOUNDARY_$(date +%s)=="

{
echo "From: [email protected]"
echo "To: $MAIL"
echo "Subject: $(hostname) : Preventive maintenance"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"$BOUNDARY\""
echo
echo "This is a multi-part message in MIME format."
echo
# Corps du mail
echo "--$BOUNDARY"
echo "Content-Type: text/plain; charset=UTF-8"
echo "Content-Transfer-Encoding: 7bit"
echo
echo "Please find the reports for the preventive maintenance of the storage $(hostname) attached."
echo
# Pièce jointe
echo "--$BOUNDARY"
echo "Content-Type: text/plain; name=\"$(basename "$REPORT")\""
echo "Content-Transfer-Encoding: base64"
echo "Content-Disposition: attachment; filename=\"$(basename "$REPORT")\""
echo
base64 "$REPORT"
echo "--$BOUNDARY--"
} | /usr/sbin/sendmail -t
}


# =========================
# MAIN PROGRAM
# =========================

general_info
summary_disk
enclosure_info
disk_info
disk_details_info
send_mail

Exemple de sortie

Exemple du contenu du fichier reçu en pièce-jointe dans le mail :

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ DATE: Fri Mar 20 13:53:32 UTC 2026
┃ HOST: server-prod-0042org
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━━━━ GENERAL INFORMATIONS
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
System: Red Hat Enterprise Linux release 9.6 (Plow)
Kernel: 5.14.0-570.21.1.el9_6.x86_64
Uptime: up 42 weeks, 42 hours, 42 minutes

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━━━━ DISKS SUMMARY
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
| EID:Slt | State | Status | Temperature | Size | Port | PFC |
---------------------------------------------------------------------------------
| 155:1 | Onln | Success | 23C | 1.60 TB | Active | 0 |
| 155:2 | Onln | Success | 22C | 1.60 TB | Active | 0 |
| 155:3 | Onln | Success | 22C | 1.60 TB | Active | 0 |
| 155:4 | Onln | Success | 22C | 1.60 TB | Active | 0 |
| 155:5 | Onln | Success | 22C | 1.60 TB | Active | 0 |
| 155:6 | Onln | Success | 22C | 1.60 TB | Active | 0 |
| 155:7 | Onln | Success | 23C | 1.60 TB | Active | 0 |
| 155:8 | DHS | Success | 23C | 1.60 TB | Active | 0 |

EID:Slt = Enclosure Device ID:Slot disk
PFC = Predictive Failure Count
DHS = Dedicated Spare Drive

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━━━━ ENCLOSURE INFORMATIONS
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Controller = 0
Status = Success
Description = None

Properties :
==========
----------------------------------------------------------------------------
EID State Slot PD PS Fans TSs Alms SIM Port# ProdID VendorSpecific
----------------------------------------------------------------------------
155 OK 8 8 0 0 0 0 0 /SAS UBM3 BC BP
----------------------------------------------------------------------------

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━━━━ DISKS INFORMATIONS
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Controller = 0
Status = Success
Description = Show Drive Information Succeeded.

Drive Information :
=================
----------------------------------------------------------------
EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp Type
----------------------------------------------------------------
155:1 1 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:2 3 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:3 2 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:4 7 DHS 0 1.60 TB NVMe SSD N N 512B N/A U -
155:5 4 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:6 5 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:7 6 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
155:8 0 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
----------------------------------------------------------------

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┣━━━━━ DISKS INFORMATIONS DETAILS
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┣━━━━━ Slot 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Controller = 0
Status = Success
Description = Show Drive Information Succeeded.

Drive /c0/e155/s1 :
=================
----------------------------------------------------------------
EID:Slt DID State DG Size Intf Med SED PI SeSz Model Sp Type
----------------------------------------------------------------
155:1 1 Onln 0 1.60 TB NVMe SSD N N 512B N/A U -
----------------------------------------------------------------
[...]

Drive /c0/e155/s1 - Detailed Information :
========================================

Drive /c0/e155/s1 State :
=======================
Shield Counter = 0
Media Error Count = 0
Other Error Count = 0
Drive Temperature = 23C (73.40 F)
Predictive Failure Count = 0

[...]

Documentation

StorCLI help

🡅 Partager