Last active
December 11, 2015 07:58
-
-
Save viljoviitanen/4570091 to your computer and use it in GitHub Desktop.
Spins down an idle disc. Made for raspberry pi raspbian wheezy, and my external usb drive which spins down with the command "sg_start -r -S".
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
#!/bin/sh | |
#spins down a disk. put this in /etc/cron.hourly so that it runs last | |
#cronjobs are run in alphabetical order so zzspindown is a sure bet... | |
#licence: public domain | |
DISK=sda | |
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 | |
$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