OK I think this is more what you want.
#!/bin/bash
MAXSPD=80
MINSPD=20
if [ $# -lt 2 ];
then
echo "Usage: setfantemp.sh <deviceid> <temp>"
exit 1
fi
DEVICE=$1
SETTEMP=$2
export DISPLAY=:0.${DEVICE}
aticonfig --pplib-cmd "set fanspeed 0 ${MAXSPD}"
while true;
do
CURTEMP=`aticonfig --adapter=${DEVICE} --odgt | grep Temp | sed 's/.* \([0-9]*[0-9][0-9]\)\..*/\1/'`
CURSPD=`aticonfig --pplib-cmd "get fanspeed 0" | grep Result | sed 's/.* \([0-9]*[0-9][0-9]\)\%.*/\1/'`
echo -n "Set temp: ${SETTEMP}C Current temp: ${CURTEMP}C Current speed: ${CURSPD}% - "
if [ "${CURTEMP}" -ne "${SETTEMP}" ]; then
if [ "${CURTEMP}" -lt "${SETTEMP}" ]; then
NEWSPD=$((${CURSPD} - 1))
if [ "${NEWSPD}" -lt "${MINSPD}" ]; then
echo "MIN speed limit"
else
echo "Decreasing speed to ${NEWSPD}"
fi
else
NEWSPD=$((${CURSPD} + 1))
if [ "${NEWSPD}" -gt "${MAXSPD}" ]; then
echo "MAX speed limit"
else
echo "Increasing speed to ${NEWSPD}"
aticonfig --pplib-cmd "set fanspeed 0 ${NEWSPD}"
fi
fi
else
echo "Stable"
fi
sleep 10
done
Save to setfantemp.sh. To run:
# ./setfantemp.sh 0 55 &
That will set your target temperature for card 0 to 55C. The script will adjust the fan speed to hit that target.
Max fan speed and min fan speed are hard coded in the script to be 80% and 20% respectively. You can raise the max speed if your card isn't getting cooled to your target temp.