Skip to content

Instantly share code, notes, and snippets.

@robertolos
Created September 6, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertolos/efb45e7c454cf15a95d013fd52b37323 to your computer and use it in GitHub Desktop.
Save robertolos/efb45e7c454cf15a95d013fd52b37323 to your computer and use it in GitHub Desktop.
Spin down usb hard drive
# 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