Created
September 6, 2018 08:20
-
-
Save robertolos/efb45e7c454cf15a95d013fd52b37323 to your computer and use it in GitHub Desktop.
Spin down usb hard drive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# activate the script via crontab as root user | |
# */5 * * * * /home/roberto/script/spinDownHd2 > /home/roberto/logspindown | |
DISK=sda | |
echo "start" | |
SGSTART=/usr/bin/sg_start | |
if [ ! -x $SGSTART ] | |
then | |
echo "$SGSTART missing. aborting." | |
exit 1 | |
fi | |
PREVIOUS=/run/.spindown-$DISK | |
#to prevent errors from the first run, create the file | |
if [ ! -f $PREVIOUS ] | |
then | |
touch $PREVIOUS | |
fi | |
# Then see if there's activity in between this run and the previous run. | |
# If not, spin down. | |
line1=`cat $PREVIOUS` | |
line2=`grep " $DISK " /proc/diskstats` | |
echo "$line2" > $PREVIOUS | |
if [ "x$line1" = "x$line2" ] | |
then | |
echo "spin down" | |
$SGSTART -r -S /dev/$DISK | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment