Created
July 28, 2017 15:37
-
-
Save t-model/b92de3222d774b6163c590893ff5a4f1 to your computer and use it in GitHub Desktop.
外付けHDDのauto spindown
This file contains hidden or 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 | |
FILELASTSTAT='/run/sdaidle_laststat' | |
FILELASTMODE='/run/sdaidle_lastmode' | |
# define | |
MODESPINDOWN="spindown" | |
MODEUP="up" | |
# | |
# from file | |
LASTSTAT=`cat $FILELASTSTAT` | |
CURSTAT=`cat /proc/diskstats | /bin/grep 'sda '` | |
LASTMODE=`cat $FILELASTMODE` | |
# debug | |
#echo "file:$FILELASTSTAT" | |
#echo "mode:$FILELASTMODE" | |
#echo "last:$LASTSTAT" | |
#echo "curr:$CURSTAT" | |
# for first boot | |
if [ ! -e $FILELASTSTAT ]; then | |
touch $FILELASTSTAT | |
fi | |
if [ ! -e $FILELASTMODE ]; then | |
touch $FILELASTMODE | |
fi | |
# | |
if [ "$LASTSTAT" = "$CURSTAT" ]; then | |
if [ ! "$LASTMODE" = "$MODESPINDOWN" ]; then | |
/sbin/hdparm -y /dev/sda | |
echo "$MODESPINDOWN" > $FILELASTMODE | |
fi | |
else | |
if [ "$LASTMODE" = "$MODESPINDOWN" ]; then | |
echo "$MODEUP" > $FILELASTMODE | |
fi | |
fi | |
echo "$CURSTAT" > $FILELASTSTAT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ODROID xu4 に接続した 外付けHDD、hdparm -m 効かないようだし、ずっと回りっぱなしなので、やっつけ作成。
spinupからだと最大30分になるがまぁ、誤差の範囲。