commit 8c4bb9cc730f4b06d8e6adb380e9de1250e72c38 Author: Ondřej Hrachovina Date: Sat Oct 19 12:52:51 2024 +0200 HDD.sh script for 1) spin down all drives except boot 2) check drives activity hdparm is needed for function diff --git a/HDD.sh b/HDD.sh new file mode 100644 index 0000000..0ae5782 --- /dev/null +++ b/HDD.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Function to display usage +show_usage() { + echo "Usage: $0 [option]" + echo "Options:" + echo " 1 Spin down drives (-y)" + echo " 2 Check drive activity (-C)" + exit 1 +} + +# Check if an option is provided +if [ -z "$1" ]; then + show_usage +fi + +# Get the boot drive (mounted as root /) +BOOT_DRIVE=$(df / | tail -1 | awk '{print $1}' | sed 's/[0-9]//g') + +# Determine the operation based on user input +case "$1" in + 1) + # Spin down drives, excluding the boot drive + for drive in /dev/sd[a-z]; do + if [[ "$drive" != "$BOOT_DRIVE" ]]; then + sudo hdparm -y $drive + fi + done + ;; + 2) + # Check drive activity, excluding the boot drive + for drive in /dev/sd[a-z]; do + if [[ "$drive" != "$BOOT_DRIVE" ]]; then + sudo hdparm -C $drive + fi + done + ;; + *) + show_usage + ;; +esac