D LINK DNS323 Fan Speed Control

D-LINK DNS-323 : Fan speed control

D-LINK DNS-323

A while ago I installed Debian jessie on my old D-LINK DNS-323 C1. I barely managed to find an installer and struggled to install it. Unfortunately an update broke it, my dlink is now unable to boot and I was unable to recover it through the serial port. But, when it worked, the fan was out of control, so I developped a bash script run in a cronjob, inspire by FIB. Now that I have my own website I can finally share it, I hope it can help someone.

 1#!/bin/sh
 2#
 3# This script was created at http://wiki.dns323.info by FIB,
 4# it has been slightly modified by leper (with help from
 5# fonz). It sets the fanspeed of the device depending on 
 6# the temperature, which is measured in Fahrenheit. If 
 7# your box measures temperature in Celsius, you need to 
 8# edit it to work.
 9# Additional changes by gartylad.
10 
11# Set the path to use RAM-disk instead of harddrive, to 
12# execute from. This is done so that the disks will go
13# into sleep mode, while the script is running.
14PATH=/usr/bin:/bin:/usr/sbin:/sbin
15 
16# T1 = temp where fan switches on
17# T2 = temp where fan switches to high
18# T3 = temp where fan switches off when it is already running
19update_interval=180
20T1=43
21T2=49
22T3=40
23
24while [ 1 ]
25do
26# get the current temperature and fan status
27T=`temperature g 0`
28T=${T##*=}
29S=`fanspeed g`
30
31if [ $S -lt 1 ]; then
32    echo "Fan status: stopped"
33    if [ $T -gt $T2 ]; then
34        echo "Fan set: high"
35        fanspeed h > /dev/null
36    elif [ $T -gt $T1 ]; then
37        echo "Fan set: low"
38        fanspeed l > /dev/null
39    fi
40else
41    echo "Fan status: running"
42    if [ $T -lt $T3 ]; then
43        echo "Fan set: stop"
44        fanspeed s > /dev/null
45    elif [ $T -lt $T2 ]; then
46        echo "Fan set: low"
47        fanspeed l > /dev/null
48    else
49        echo "Fan set: high"
50        fanspeed h > /dev/null
51    fi
52fi 
53
54sleep $update_interval
55done