Tuesday, September 22, 2009

Re: [nslu2-linux] scsi-stop and cron-job?

 

Hi Mai Kee,
you can read /sys/block/<dev>/stat (with <dev> corresponding to your
HDD, eg. sdb) and look for changes. After a certain timeout you could
issue your scsi-stop command.
Altough my disk on a TS-109 could spin down automatically, I use such a
script to be able to take other aspects into account - the disk will
never spin down as long as I have one of its NFS shares mounted from my
PC.

That's my script:

=========================================
#!/bin/sh

#DEV=sdb
DEV=`blkid -t LABEL=MEDIA | sed 's/[0-9].*//'`
DEV=${DEV#/dev/}
STATFILE=/sys/block/$DEV/stat
RMTAB="/var/lib/nfs/rmtab"
let 'CYCLES=10*60/5'
LOGFILE=/var/log/spindown.log
state=active

rw=0
count=0
echo "" >> $LOGFILE
date "+%D %T - start" >> $LOGFILE
while true ; do
rw_old=$rw
read reads a2 a3 a4 writes rest < $STATFILE
let "rw=$reads+$writes"
if [ "$rw" != "$rw_old" -o -s "$RMTAB" ] ; then
count=0
state=active
lastacc="`date '+%D %T - idle'`"
else
if [ "$state" = "active" ] ; then
let "count=$count+1"
fi
fi
if [ "$state" = "active" -a $count -gt $CYCLES ] ; then
echo "$lastacc" >> $LOGFILE
date "+%D %T - spindown" >> $LOGFILE
hdparm -Y /dev/$DEV
state=standby
fi
sleep 5
done
=========================================

You will probably need to tweak it a bit, eg. set DEV=sdb or change the
disk LABEL, remove the code watching $RMTAB, or maybe do not write a log
file (especially if your /var/log directory is not located on a ram
disk). And of course "hdparm -Y" should be your scsi-stop command.
The script will wait for 10 minutes of inactivity, set via CYCLES.

Hope that helps.
-Thomas

Am Dienstag, den 22.09.2009, 19:02 +0200 schrieb Mai Kee Reis:
> Can anybody please give me a hint how to spin down my HDD if not used a while?
> My system is a NSLU2 with SlugOS 5.3 LE.
>
> The following does work fine, if invoked manually:
> /opt/sbin/scsi-stop /dev/sdb
>
> So I think about using cron - good idea?
>
> Or will this cause trouble to attached processes? (Samba,...)
> I'm not shure, but I think I saw a solution with crontab + some
> kind of disk statistics, but can't google or remember anymore
>
> (invoking '/opt/sbin/scsi-idle /dev/sdb 180' does not do the job
> as it shall by documentation)
>
> Greetings,
> Mai Kee
>
>
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>

__._,_.___
Recent Activity
Visit Your Group
Give Back

Yahoo! for Good

Get inspired

by a good cause.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___

No comments:

Post a Comment