script for 1) spin down all drives except boot 2) check drives activity hdparm is needed for function
42 lines
945 B
Bash
42 lines
945 B
Bash
#!/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
|