<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Howto: Automatically spin down external usb hard drives in Ubuntu</title>
	<atom:link href="http://hartvig.de/2009/howto-automatically-spin-down-external-usb-hard-drives-in-ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://hartvig.de/2009/howto-automatically-spin-down-external-usb-hard-drives-in-ubuntu/</link>
	<description>Personal homepage of Kaare Hartvig Jensen</description>
	<lastBuildDate>Mon, 02 Apr 2012 06:05:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: dirk</title>
		<link>http://hartvig.de/2009/howto-automatically-spin-down-external-usb-hard-drives-in-ubuntu/#comment-97784</link>
		<dc:creator>dirk</dc:creator>
		<pubDate>Mon, 02 Apr 2012 06:05:11 +0000</pubDate>
		<guid isPermaLink="false">http://hartvig.de/?p=348#comment-97784</guid>
		<description>I added some checks and logging to the script...
Now the spindown isn&#039;t issued as long as the drive hasn&#039;t spin up again.

# !/bin/sh

TMPF1=&quot;/tmp/.hddspindwn-$1-1&quot;
TMPF2=&quot;/tmp/.hddspindwn-$1-2&quot;
FLAG=&quot;/tmp/.hddspindwnflg-$1&quot;
LOG_FILE=/var/log/hddspindown.log
STAMP=`date +&quot;%d.%m.%g %H:%M:%S&quot;`

[ &quot;.$1&quot; != &quot;.&quot; ] &amp;&amp; disks=$(ls /dev/sd* &#124; grep $1)
if [ &quot;.$disks&quot; = &quot;.&quot; ]; then
  echo &quot;Please enter a valid disk device&quot; 1&gt;&amp;2
  exit 1;
fi

if [ &quot;$(id -u)&quot; != &quot;0&quot; ]; then
  echo &quot;This script must be run as root&quot; 1&gt;&amp;2
  exit 1
fi

# Get new state from diskstats
nstats=$(cat /proc/diskstats &#124; grep $1)
echo $nstats &gt; $TMPF1

# compare md5 sums
nmd5=&quot;???&quot;
omd5=&quot;???&quot;
[ -f $TMPF1 ] &amp;&amp; nmd5=$(md5sum $TMPF1 &#124; sed &#039;s/ .*//&#039;)
[ -f $TMPF2 ] &amp;&amp; omd5=$(md5sum $TMPF2 &#124; sed &#039;s/ .*//&#039;)
echo &quot;$STAMP : Current MD5 : $nmd5&quot; &gt;&gt; $LOG_FILE
echo &quot;$STAMP : Old MD5     : $omd5&quot; &gt;&gt; $LOG_FILE

# if no changes, power down
if [ &quot;$nmd5&quot; = &quot;$omd5&quot; ]; then
  if [ ! -f $FLAG ]; then
    touch $FLAG
    hdparm -Y /dev/$1 &amp;&gt;/dev/null
    echo &quot;$STAMP : Spindown of /dev/$1 intiated...&quot; &gt;&gt; $LOG_FILE
  else
    echo &quot;$STAMP : /dev/$1 was already set to standby.&quot; &gt;&gt; $LOG_FILE
  fi
else
  if [ -f $FLAG ]; then
    rm $FLAG
    echo &quot;$STAMP : $FLAG removed because of disk-io.&quot; &gt;&gt; $LOG_FILE
  fi
fi

# Write current state to file
echo $nstats &gt; $TMPF2</description>
		<content:encoded><![CDATA[<p>I added some checks and logging to the script&#8230;<br />
Now the spindown isn&#8217;t issued as long as the drive hasn&#8217;t spin up again.</p>
<p># !/bin/sh</p>
<p>TMPF1=&#8221;/tmp/.hddspindwn-$1-1&#8243;<br />
TMPF2=&#8221;/tmp/.hddspindwn-$1-2&#8243;<br />
FLAG=&#8221;/tmp/.hddspindwnflg-$1&#8243;<br />
LOG_FILE=/var/log/hddspindown.log<br />
STAMP=`date +&#8221;%d.%m.%g %H:%M:%S&#8221;`</p>
<p>[ ".$1" != "." ] &amp;&amp; disks=$(ls /dev/sd* | grep $1)<br />
if [ ".$disks" = "." ]; then<br />
  echo &#8220;Please enter a valid disk device&#8221; 1&gt;&amp;2<br />
  exit 1;<br />
fi</p>
<p>if [ "$(id -u)" != "0" ]; then<br />
  echo &#8220;This script must be run as root&#8221; 1&gt;&amp;2<br />
  exit 1<br />
fi</p>
<p># Get new state from diskstats<br />
nstats=$(cat /proc/diskstats | grep $1)<br />
echo $nstats &gt; $TMPF1</p>
<p># compare md5 sums<br />
nmd5=&#8221;???&#8221;<br />
omd5=&#8221;???&#8221;<br />
[ -f $TMPF1 ] &amp;&amp; nmd5=$(md5sum $TMPF1 | sed &#8216;s/ .*//&#8217;)<br />
[ -f $TMPF2 ] &amp;&amp; omd5=$(md5sum $TMPF2 | sed &#8216;s/ .*//&#8217;)<br />
echo &#8220;$STAMP : Current MD5 : $nmd5&#8243; &gt;&gt; $LOG_FILE<br />
echo &#8220;$STAMP : Old MD5     : $omd5&#8243; &gt;&gt; $LOG_FILE</p>
<p># if no changes, power down<br />
if [ "$nmd5" = "$omd5" ]; then<br />
  if [ ! -f $FLAG ]; then<br />
    touch $FLAG<br />
    hdparm -Y /dev/$1 &amp;&gt;/dev/null<br />
    echo &#8220;$STAMP : Spindown of /dev/$1 intiated&#8230;&#8221; &gt;&gt; $LOG_FILE<br />
  else<br />
    echo &#8220;$STAMP : /dev/$1 was already set to standby.&#8221; &gt;&gt; $LOG_FILE<br />
  fi<br />
else<br />
  if [ -f $FLAG ]; then<br />
    rm $FLAG<br />
    echo &#8220;$STAMP : $FLAG removed because of disk-io.&#8221; &gt;&gt; $LOG_FILE<br />
  fi<br />
fi</p>
<p># Write current state to file<br />
echo $nstats &gt; $TMPF2</p>
]]></content:encoded>
	</item>
</channel>
</rss>

