Created
July 30, 2011 11:49
-
-
Save apnof/1115443 to your computer and use it in GitHub Desktop.
shellscript - avoid hdd spin-down.
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 | |
# this script finds out the mountpoint for the given DISKLABEL | |
# and touches the file ${MOUNTPOINT}/tempfile periodically every | |
# INTERVAL. | |
# adjust the following two values. | |
DISKLABEL="WD_500G_NTFS" | |
INTERVAL="5s" | |
# get line with our disklabel | |
MOUNTLINE=$(mount -l | grep "$DISKLABEL"); | |
# check if mounted | |
if [ "$MOUNTLINE" == "" ] | |
then | |
echo "Error: Partition with disklabel $DISKLABEL not mounted." | |
exit 1 | |
fi | |
# get mountpoint | |
# FIXME: | |
# not sure if awk command always returns | |
# the correct mountpoint or an empty string... | |
MOUNTPOINT=$(echo $MOUNTLINE | awk '{ print $3 }') | |
# check if mountpoint begins with /media/ to prevent errors by | |
# mountpoint extraction above. | |
# dirty. problem when partition is mounted somewhere else.. :-( | |
(echo $MOUNTPOINT | grep "\/media\/") &> /dev/null; RC=$? | |
if ! [ "$RC" = 0 ] | |
then | |
echo "Error: problem extracting mountpoint." | |
exit 2 | |
fi | |
echo "Found mountpoint for partition labeled '$DISKLABEL' at '$MOUNTPOINT'." | |
echo "Touching and syncing ${MOUNTPOINT}/tempfile every ${INTERVAL}..." | |
echo "Quit with ^C." | |
while true | |
do | |
touch ${MOUNTPOINT}/tempfile | |
sleep ${INTERVAL} | |
sync | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment