Created
October 15, 2013 12:18
-
-
Save cdfmr/6990704 to your computer and use it in GitHub Desktop.
Spin down usb hard disk automatically if there is no activity |
Depends: hdparm sdparm |
Cron: */15 * * * * spindown.sh sda 10 (spin down sda if there is no activity for 10 minutes)
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 | |
DISK=sda | |
TIMEOUT=600 | |
if [ $# -ge 1 ] ; then | |
DISK=$1 | |
fi | |
if [ $# -ge 2 ] ; then | |
TIMEOUT=$2 | |
TIMEOUT=$((TIMEOUT*60)) | |
fi | |
status=`hdparm -C /dev/$DISK | grep -o standby` | |
if [ "$status" = "standby" ] ; then | |
exit 0 | |
fi | |
for i in `seq 1 $TIMEOUT` ; do | |
io=`cat /proc/diskstats | grep "$DISK " | awk '{print $(NF-2)}'` | |
if [ $io -gt 0 ] ; then | |
exit 0 | |
fi | |
sleep 1 | |
done | |
logger "Sending standby command to /dev/$DISK" | |
sdparm -C stop /dev/$DISK > /dev/null | |
exit 0 |
For the record, you need to pass
-r
(readonly) for modern disks:sdparm -C stop -r /dev/sdd
Thanks. The -r
parameter is not available for old sdparm versions, at least not available for my openwrt router.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record, you need to pass
-r
(readonly) for modern disks: