From f27f5c1ddb80ada4e23752cc719477b8e93ab7f1 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Wed, 20 May 2026 09:21:01 +0200 Subject: [PATCH] =?UTF-8?q?zfs-spindown.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zfs-spindown.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 zfs-spindown.sh diff --git a/zfs-spindown.sh b/zfs-spindown.sh new file mode 100644 index 0000000..e3f233f --- /dev/null +++ b/zfs-spindown.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# KONFIGURATION +DRIVES=("sda" "sdb" "sdc" "sdd" "sde") +IDLE_TIME=600 # 10 Minuten (in Sekunden) +CHECK_INTERVAL=60 # Prüf-Intervall (1 Minute) + +declare -A last_sector_count +declare -A last_activity + +echo "ZFS-Spindown-Watchdog gestartet. Monitoring für: ${DRIVES[*]}" + +# Initialisierung der Start-Werte +for drive in "${DRIVES[@]}"; do + last_sector_count[$drive]=0 + last_activity[$drive]=$(date +%s) +done + +while true; do + current_time=$(date +%s) + + for drive in "${DRIVES[@]}"; do + if [ -f "/sys/block/$drive/stat" ]; then + # Sektoren auslesen (Spalte 3 = Read, Spalte 7 = Write) + stats=$(cat "/sys/block/$drive/stat") + read_sectors=$(echo $stats | awk '{print $3}') + write_sectors=$(echo $stats | awk '{print $7}') + current_sectors=$((read_sectors + write_sectors)) + + # Prüfen, ob sich die Sektoren-Anzahl seit dem letzten Check geändert hat + if [ "$current_sectors" -ne "${last_sector_count[$drive]}" ]; then + diff=$((current_sectors - last_sector_count[$drive])) + echo "[$(date '+%H:%M:%S')] Aktivität auf $drive: $diff Sektoren. Timer resettet." + last_sector_count[$drive]=$current_sectors + last_activity[$drive]=$current_time + else + # Wenn keine Aktivität, berechne die verstrichene Zeit + elapsed=$((current_time - last_activity[$drive])) + + if [ "$elapsed" -ge "$IDLE_TIME" ]; then + # Nur Befehl senden, wenn Platte nicht schon im Standby ist + status=$(/sbin/hdparm -C "/dev/$drive" 2>/dev/null) + if [[ "$status" == *"active/idle"* ]]; then + echo "[$(date '+%H:%M:%S')] $drive ist seit $((elapsed/60)) Min idle. Schicke sie in den Standby..." + /sbin/hdparm -y "/dev/$drive" > /dev/null 2>&1 + fi + fi + fi + fi + done + + sleep $CHECK_INTERVAL +done \ No newline at end of file