Copyright (C) 2008-2021 Oliver Bohlen.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU Free Documentation License".
This documentation comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
You can check the current power state with
hdparm -C /dev/diskPlease be caraful with this solution. If you set the timeout to low it is possible that your disk is spinning up an down very often which is noch very good for your hardware...
If you want to use this solution you need the following howto(s) finished:
emerge sys-apps/hdparm
File permissions:
Owner: root
Group: root
Permissions: -rw-r--r--
Click here for a download of the complete file: /etc/crontab
Changed on 30.11.10Shutdown /dev/sdb if it is inactive
*/5 * * * * root /usr/local/sbin/hdspindown.sh sdb
File permissions:
Owner: root
Group: root
Permissions: -rwxr-xr-x
Click here for a download of the complete file: /usr/local/sbin/hdspindown.sh
Changed on 30.11.10This is a small script to observe the inactivity of given disk(s). If the given disks are longer then $inactive minutes inactive they will be spinned down and set to sleep (e.g. for powersaving). If a disk ist shutdown a mail will be sent to root.
#!/bin/bash
# Time of inactivity after which the disk is spinned down
inactive=30
# Get default profile
. /etc/profile
# Function for checking the disks state
function checkactive {
# If the disk is not spinned down - shutdown the disk
if hdparm -C /dev/$1 | grep active >/dev/null
then
echo "`date` Spinning down $1" >> /tmp/spinned-down
echo "1" >/tmp/spindown$1
spindown $1
# else
# echo "`date` Already spinned down $1" >> /tmp/spinned-down
fi
}
# Function for sending a mail and spindown the disk
function spindown {
echo "Issuing sleep on disk $1:
`ls -l /sys/block/$1/stat`
`cat /sys/block/$1/stat`
`ls -l /tmp/$1-stat`
`cat /tmp/$1-stat`
Date: `date`
Issuing command: hdparm -y /dev/$1:
`hdparm -y /dev/$1 2>&1`
" | mail -s "Spinning down $1" root
}
# Check commandline
if [ $# -eq 0 ]
then
echo "This is a small script to observe the inactivity of given disk(s). If the given disks are longer then $inactive minutes inactive they will be spinned down and set to sleep (e.g. for powersaving). If a disk ist shutdown a mail will be sent to root.
Please enter the disk(s) you want do observe seperated with space. E.g for observing /dev/hdb and /dev/sda:
$0 hdb sda"
exit 1
fi
# Go through the arguments
for disk in $*
do
# If the disk exists
if [ -L "/sys/block/$disk" ]
then
# Create diff-file if it dows not exist
[ -f /tmp/$disk-stat ] || touch /tmp/$disk-stat
# If there was nothing changed
if diff /sys/block/$disk/stat /tmp/$disk-stat >/dev/null 2>&1
then
# Check weather the disk is longer then $inactive inactive
find /tmp/$disk-stat -mmin -$inactive | grep $disk >/dev/null || checkactive $disk
# If the file is changed
else
# Save changed file
cat /sys/block/$disk/stat > /tmp/$disk-stat
if [ -f /tmp/spindown$disk ]
then
echo "Disk $disk active again" | mail -s "$disk active again" root
echo "`date` Disk active: $disk" >> /tmp/spinned-down
rm -f /tmp/spindown$disk
fi
# echo "`date` Disk active: $disk" >> /tmp/spinned-down
fi
# If the disk does not exist
else
echo "Disk $disk seems not to exist"
fi
done
Please send a feedback to: doc<at>gabosh.net
Howto listingHere you can find the official Gentoo Linux Forums where you can find a lot of answers.
Here a link to the official Gentoo Linux Homepage.