Fan Control
From NAS-Central Buffalo - The Linkstation Wiki
(Difference between revisions)
(added section 3 with a "catch-all" script) |
(→Method 3) |
||
| Line 87: | Line 87: | ||
== Method 3 == | == Method 3 == | ||
| + | |||
| + | To install this one : | ||
| + | * Become root <br> #su | ||
| + | * Create a directory for your scripts <br> # mkdir /usr/scripts | ||
| + | * Create a new file <br> # vim /usr/scripts/fanctrl | ||
| + | ** Paste the script in there, than save and exit (enter :x, if on vim) | ||
| + | * Make the file executable <br> # chmod 755 /usr/scripts/fanctrl | ||
| + | * Edit your crontab (vim /etc/crontab) and add this line: | ||
| + | <pre>*/7 * * * * Root /eusr/scripts/fanctrl</pre> | ||
| + | |||
<pre> | <pre> | ||
#!/bin/sh | #!/bin/sh | ||
Revision as of 06:16, 24 May 2007
Method 1
http://spock.ss.u-tokai.ac.jp/~kamii/kurobox/hddtemp.shtml
% cat /usr/local/bin/HDDtempChk
#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
export PATH
REC=/var/spool/rwho/ondorec
LOG=/var/spool/rwho/temp
time=`date '+%y-%m-%d %H:%M'`
data=`hddtemp -nq $1`
ondo=`expr "$data" : '.*: *\([0-9][0-9]*\)[^0-9]*'`
fastspeed()
{
/bin/echo -n ']]]]' > /dev/ttyS1
}
slowspeed()
{
/bin/echo -n '\\\\' > /dev/ttyS1
}
if [ -f $REC ] ; then
count=`cat $REC`
else
echo 0 > $REC
count=-1
fi
if [ $ondo -ge $2 ] ; then
count=`expr $count + 1`
echo $count > $REC
if [ $count -lt 3 ] ; then
ACT=fastspeed
elif [ $count -eq 3 ] ; then
ACT=slowspeed
else
ACT=
fi
else
if [ $count -ne 0 ] ; then
ACT=slowspeed
echo 0 > $REC
else
ACT=
fi
fi
echo "$time $data ($ondo : $2) $ACT" >> $LOG
tail -24 $LOG > ${LOG}x
mv ${LOG}x $LOG
#exit
if [ "$ACT" = "fastspeed" ] ; then
fastspeed
elif [ "$ACT" = "slowspeed" ] ; then
slowspeed
fi
exit
Method 2
http://www.kurobox.info/bbs/index.php?showtopic=550
# Check HD temperature to control the fan speed
#
MAX_TEMP=35
HD_TEMP=`smartctl -A /dev/hda | awk '/^194/ { print($10) }'`
# AVR
#
TTY="/dev/ttyS1"
STR_L="\\\\"
STR_H="]]]]"
# ... check temperature and "silence" the fan
if [ $HD_TEMP -lt $MAX_TEMP ]; then
# tell the AVR Low-speed
echo -n "${STR_L}" > $TTY
else
# tell the AVR High-speed
echo -n "${STR_H}" > $TTY
fi
Method 3
To install this one :
- Become root
#su - Create a directory for your scripts
# mkdir /usr/scripts - Create a new file
# vim /usr/scripts/fanctrl- Paste the script in there, than save and exit (enter :x, if on vim)
- Make the file executable
# chmod 755 /usr/scripts/fanctrl - Edit your crontab (vim /etc/crontab) and add this line:
*/7 * * * * Root /eusr/scripts/fanctrl
#!/bin/sh
#
if [ $# -ne 1 ]; then
cat 2>&1 << EOF
##############################################
fanctrl
-------
purpose: adjusts Kurobox fan speed based on supplied argument
author: Mathias Weiersmueller ( matti_at_weiersmuellerdotcom )
version: 1.0
date: 20060917
license: LGPL, no warranty, use at your own risk
arguments:
auto = sets fan to low/high speed depending on current temp
(based in variable HD_TEMP)
low = sets fan to low speed
high = sets fan to high speed
(number) = sets fan to high speed if HD temp is
equal or higher than (number), or to low speed
if HD temp is lower
###############################################
EOF
exit 127
fi
MAX_TEMP=37 # this is Celsius, not Fahrenheit
HD_TEMP=`/usr/sbin/hddtemp -nq /dev/hda`
# AVR
#
TTY="/dev/ttyS1"
STR_L="\\\\"
STR_H="]]]]"
###############################
# functions
fanlow() {
echo -n "${STR_L}" > $TTY
echo LOW
}
fanhigh() {
echo -n "${STR_H}" > $TTY
echo HIGH
}
################################
# main
case $1 in
auto)
if [ $HD_TEMP -ge $MAX_TEMP ]
then fanhigh
else fanlow
fi
;;
low)
fanlow
;;
high)
fanhigh
;;
-h|--help|-help|-\?)
exec fanctrl # calls fanctrl without arguments, thus displaying help...
;;
*)
if expr "$1" : "[0-9][0-9]" >/dev/null # check for 2-digit number
then
if [ $HD_TEMP -ge $1 ]
then fanhigh
else fanlow
fi
else echo "error: wrong arguments";exit 127;
fi
;;
esac

