Got a feature request? Great! Post your ideas here!
VladK
Posts: 8 youtube meble na wymiar Warszawa
Joined: Tue Jan 25, 2022 12:06 am
Post
by VladK » Wed Jan 26, 2022 7:17 pm
Last version:
Code: Select all
#!/bin/sh
if [ "$1" = "-v" ]
then
VERBOSE=1
fi
FANID=0
DEF_DESIREDPOWER=75 # from about 30 to 255
CYCLETEMPCHECK=18 # every how many 10" cycles we check for temp changes. 6 = every mn
#
# temperature to power grid : GRIDxx=yy : we want power of yy if temp is xx
GRID15=30 ; GRID16=30 ; GRID17=30 ; GRID18=31 ; GRID19=33
GRID20=35 ; GRID21=37 ; GRID22=39 ; GRID23=41 ; GRID24=44
GRID25=47 ; GRID26=50 ; GRID27=54 ; GRID28=59 ; GRID29=65
GRID30=68 ; GRID31=70 ; GRID32=72 ; GRID33=74 ; GRID34=75
GRID35=77 ; GRID36=79 ; GRID37=82 ; GRID38=84 ; GRID39=85
GRID40=86 ; GRID41=88 ; GRID42=90 ; GRID43=92 ; GRID44=94
GRID45=96 ; GRID46=98 ; GRID47=99 ; GRID48=100 ; GRID49=110
GRID50=120 ; GRID51=130 ; GRID52=140 ; GRID53=150 ; GRID54=160
GRID55=170 ; GRID56=180 ; GRID57=190 ; GRID58=210 ; GRID59=230
GRID60=250 ; GRID61=250 ; GRID62=250 ; GRID63=250 ; GRID64=250
#
# let's learn devices which have temperature sensors
#
HOTTESTDISKTEMP=15
LSTDEVICES=""
for DSKDEV in /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj
do
df | grep $DSKDEV | grep USB >/dev/null 2>&1
if [ $? -ne 0 ]
then
TSTTEMP=`/usr/builtin/sbin/smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
if [ "$TSTTEMP" != "" ]
then
if [ \( "$TSTTEMP" -gt 15 \) -a \( "$TSTTEMP" -lt 70 \) ]
then
[ $VERBOSE ] && echo $DSKDEV added to list with recognized temp of $TSTTEMP
LSTDEVICES="$LSTDEVICES $DSKDEV"
fi
fi
fi
done
[ $VERBOSE ] && echo Retained devices for temperature check : $LSTDEVICES
# DESIREDPOWER=$DEF_DESIREDPOWER # from about 30 to 255
DESIREDPOWER=`fanctrl -getfanspeed|awk ' { print $NF } '`
COUNTDWN=0
CPT=0
DELAY=1 # initial loop = no delay
while :
do
#
# temperature check
#
if [ $COUNTDWN -le 0 ]
then
COUNTDWN=$CYCLETEMPCHECK
# we almost cancel pause because this loop consumes time.
DELAY=1
NEW_HOTTESTDISKTEMP=15
for DSKDEV in $LSTDEVICES
do
TSTTEMP=`/usr/builtin/sbin/smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
if [ "$TSTTEMP" -gt $NEW_HOTTESTDISKTEMP ]
then
NEW_HOTTESTDISKTEMP=$TSTTEMP
fi
done
NEW_DESIREDPOWER=`eval echo \\\$GRID$NEW_HOTTESTDISKTEMP`
if [ "$NEW_DESIREDPOWER" = "" ]
then
NEW_DESIREDPOWER=$DEF_DESIREDPOWER
fi
if [ $HOTTESTDISKTEMP != $NEW_HOTTESTDISKTEMP ]
then
if [ $DESIREDPOWER != $NEW_DESIREDPOWER ]
then
[ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP,raising fanpower from $DESIREDPOWER to $NEW_DESIREDPOWER
DESIREDPOWER=$NEW_DESIREDPOWER
else
[ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP,fanpower leaved unchanged at $DESIREDPOWER
fi
HOTTESTDISKTEMP=$NEW_HOTTESTDISKTEMP
## else
## [ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk leaved unchanged at $HOTTESTDISKTEMP ,fanpower leaved unchanged at $DESIREDPOWER
fi
fi
#
# fan override loop
#
CURRPOWER=`fanctrl -getfanspeed|awk ' { print $NF } ' `
if [ $DESIREDPOWER -ne $CURRPOWER ]
then
fanctrl -setfanpwm 0 $DESIREDPOWER # fan 0
fanctrl -setfanpwm 1 $DESIREDPOWER # fan 1
## echo $CURRPOWER to $DESIREDPOWER CPT : $CPT
CPT=0
COUNTDWN=`expr $COUNTDWN - 1`
sleep $DELAY
DELAY=9
else
sleep 0.1
CPT=`expr $CPT + 1`
fi
done
result
Code: Select all
root@AS7010T-6EBB:/volume1/.@root # ./smart_fanspeed.sh -v
/dev/sda added to list with recognized temp of 34
/dev/sdb added to list with recognized temp of 36
/dev/sdc added to list with recognized temp of 36
/dev/sdd added to list with recognized temp of 38
/dev/sde added to list with recognized temp of 39
/dev/sdf added to list with recognized temp of 37
/dev/sdg added to list with recognized temp of 36
/dev/sdh added to list with recognized temp of 38
Retained devices for temperature check : /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh
sh: 52: unknown operand
20220126_14:11:37 hottest disk changed from 15 to 39,fanpower leaved unchanged at 52 52
sh: 52: unknown operand
sh: 52: unknown operand
sh: 52: unknown operand
j-rune
Posts: 6 Joined: Fri Apr 10, 2020 8:50 pm
Post
by j-rune » Wed Jan 26, 2022 7:32 pm
Here's my full smart fan script.
Code: Select all
#!/bin/sh
if [ "$1" = "-v" ]
then
VERBOSE=1
fi
FANID=0 # not used, we have two (2) fans.
DEF_DESIREDPOWER=75 # from about 30 to 255
CYCLETEMPCHECK=30 # every how many 10" cycles we check for temp changes. 6 = every mn. Set to 5 minutes.
#
# temperature to power grid : GRIDxx=yy : we want power of yy if temp is xx
#GRID15=30 ; GRID16=30 ; GRID17=30 ; GRID18=31 ; GRID19=33
#GRID20=35 ; GRID21=37 ; GRID22=39 ; GRID23=41 ; GRID24=44
#GRID25=47 ; GRID26=50 ; GRID27=54 ; GRID28=59 ; GRID29=65
#GRID30=68 ; GRID31=70 ; GRID32=72 ; GRID33=74 ; GRID34=75
#GRID35=77 ; GRID36=79 ; GRID37=82 ; GRID38=84 ; GRID39=85
#GRID40=86 ; GRID41=88 ; GRID42=90 ; GRID43=92 ; GRID44=94
#GRID45=96 ; GRID46=98 ; GRID47=99 ; GRID48=100 ; GRID49=110
#GRID50=120 ; GRID51=130 ; GRID52=140 ; GRID53=150 ; GRID54=160
#GRID55=170 ; GRID56=180 ; GRID57=190 ; GRID58=210 ; GRID59=230
#GRID60=250 ; GRID61=250 ; GRID62=250 ; GRID63=250 ; GRID64=250
# low=45
# medium=104
# high=164
GRID15=30 ; GRID16=30 ; GRID17=30 ; GRID18=31 ; GRID19=33
GRID20=35 ; GRID21=37 ; GRID22=39 ; GRID23=41 ; GRID24=44
GRID25=45 ; GRID26=45 ; GRID27=45 ; GRID28=45 ; GRID29=47
GRID30=50 ; GRID31=50 ; GRID32=50 ; GRID33=55 ; GRID34=55
GRID35=55 ; GRID36=60 ; GRID37=60 ; GRID38=60 ; GRID39=63
GRID40=63 ; GRID41=63 ; GRID42=67 ; GRID43=70 ; GRID44=75
GRID45=75 ; GRID46=85 ; GRID47=85 ; GRID48=95 ; GRID49=95
GRID50=104 ; GRID51=104 ; GRID52=104 ; GRID53=150 ; GRID54=160
GRID55=164 ; GRID56=164 ; GRID57=164 ; GRID58=164 ; GRID59=164
GRID60=250 ; GRID61=250 ; GRID62=250 ; GRID63=250 ; GRID64=250
[ $VERBOSE ] && echo "Temperature to power grid : GRIDxx=yy : we want power of yy if temp is xx"
[ $VERBOSE ] && echo "GRID15=30 ; GRID16=30 ; GRID17=30 ; GRID18=31 ; GRID19=33"
[ $VERBOSE ] && echo "GRID20=35 ; GRID21=37 ; GRID22=39 ; GRID23=41 ; GRID24=44"
[ $VERBOSE ] && echo "GRID25=45 ; GRID26=45 ; GRID27=45 ; GRID28=45 ; GRID29=47"
[ $VERBOSE ] && echo "GRID30=50 ; GRID31=50 ; GRID32=50 ; GRID33=55 ; GRID34=55"
[ $VERBOSE ] && echo "GRID35=55 ; GRID36=60 ; GRID37=60 ; GRID38=60 ; GRID39=63"
[ $VERBOSE ] && echo "GRID40=63 ; GRID41=63 ; GRID42=67 ; GRID43=75 ; GRID44=75"
[ $VERBOSE ] && echo "GRID45=75 ; GRID46=85 ; GRID47=85 ; GRID48=95 ; GRID49=95"
[ $VERBOSE ] && echo "GRID50=104 ; GRID51=104 ; GRID52=104 ; GRID53=150 ; GRID54=160"
[ $VERBOSE ] && echo "GRID55=164 ; GRID56=164 ; GRID57=164 ; GRID58=164 ; GRID59=164"
[ $VERBOSE ] && echo "GRID60=250 ; GRID61=250 ; GRID62=250 ; GRID63=250 ; GRID64=250"
#
# let's learn devices which have temperature sensors
#
HOTTESTDISKTEMP=15
LSTDEVICES=""
for DSKDEV in /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh
do
df | grep $DSKDEV | grep USB >/dev/null 2>&1
if [ $? -ne 0 ]
then
TSTTEMP=`/usr/builtin/sbin/smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
if [ "$TSTTEMP" != "" ]
then
if [ \( "$TSTTEMP" -gt 15 \) -a \( "$TSTTEMP" -lt 70 \) ]
then
[ $VERBOSE ] && echo $DSKDEV added to list with recognized temp of $TSTTEMP
LSTDEVICES="$LSTDEVICES $DSKDEV"
fi
fi
fi
done
[ $VERBOSE ] && echo Retained devices for temperature check : $LSTDEVICES
# DESIREDPOWER=$DEF_DESIREDPOWER # from about 30 to 255
DESIREDPOWER=`fanctrl -getfanspeed|awk 'NR==1{ print $NF } '` # Only read the first line and determine the current fan speed, because we have two fans operating at the exact same speed.
COUNTDWN=0
CPT=0
DELAY=1 # initial loop = no delay
while :
do
#
# temperature check
#
if [ $COUNTDWN -le 0 ]
then
COUNTDWN=$CYCLETEMPCHECK
# we almost cancel pause because this loop consumes time.
DELAY=1
NEW_HOTTESTDISKTEMP=15
for DSKDEV in $LSTDEVICES
do
TSTTEMP=`/usr/builtin/sbin/smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
if [ "$TSTTEMP" -gt $NEW_HOTTESTDISKTEMP ]
then
NEW_HOTTESTDISKTEMP=$TSTTEMP
fi
done
NEW_DESIREDPOWER=`eval echo \\\$GRID$NEW_HOTTESTDISKTEMP`
if [ "$NEW_DESIREDPOWER" = "" ]
then
NEW_DESIREDPOWER=$DEF_DESIREDPOWER
fi
if [ $HOTTESTDISKTEMP != $NEW_HOTTESTDISKTEMP ]
then
if [ $DESIREDPOWER != $NEW_DESIREDPOWER ]
then
[ $VERBOSE ] && echo `date +%Y%m%d-%T` Hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP, Changing fanpower from $DESIREDPOWER to $NEW_DESIREDPOWER
DESIREDPOWER=$NEW_DESIREDPOWER
else
[ $VERBOSE ] && echo `date +%Y%m%d-%T` Hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP, Fanpower left unchanged at $DESIREDPOWER
fi
HOTTESTDISKTEMP=$NEW_HOTTESTDISKTEMP
##else
## [ $VERBOSE ] && echo `date +%Y%m%d_%T` Hottest disk left unchanged at $HOTTESTDISKTEMP, Fanpower left unchanged at $DESIREDPOWER
fi
fi
#
# fan override loop
#
CURRPOWER=`fanctrl -getfanspeed|awk 'NR==1 { print $NF } ' `
if [ $DESIREDPOWER -ne $CURRPOWER ]
then
fanctrl -setfanpwm 0 $DESIREDPOWER # fan 0
fanctrl -setfanpwm 1 $DESIREDPOWER # fan 1
## echo $CURRPOWER to $DESIREDPOWER CPT : $CPT
CPT=0
COUNTDWN=`expr $COUNTDWN - 1`
sleep $DELAY
DELAY=9
# [ $VERBOSE ] && echo `date +%Y%m%d-%T` Fan0, `fanctrl -getfanspeed|awk 'NR==1 '`
# [ $VERBOSE ] && echo `date +%Y%m%d-%T` Fan1, `fanctrl -getfanspeed|awk 'NR==2 '`
else
sleep 0.1
CPT=`expr $CPT + 1`
fi
done
VladK
Posts: 8 Joined: Tue Jan 25, 2022 12:06 am
Post
by VladK » Wed Jan 26, 2022 8:17 pm
Thanks everyone for the help, the last script is working. For my system (7010T on i3), the power figures are as follows:
# low=20 (514-542RPM)
# medium=36 (1207-1227RPM)
# high=52 (1804-1814RPM)
For 63 - 2163-2177RPM
sksbir
Posts: 395 Joined: Tue Aug 25, 2015 9:23 pm
Post
by sksbir » Sat Apr 23, 2022 5:31 am
hello
sorry, I missed your post
I have updated smart_fanspeed.sh with several improvments, including the management of more than one fan.
regarding problem of script, my opinion is : bad copy-paste. I tested the offending script, and it was working, out of hardcoded fan set wich don't exists on my NAS.
ekz
Posts: 2 Joined: Thu Nov 09, 2023 12:41 am
Post
by ekz » Sat Nov 25, 2023 12:30 am
Here is my implementation of this script:
https://github.com/Erellariss/asustor-s ... /tree/main
Advantages:
- Much more readable;
- Has negative feedback cycle to calculate next fan change (via sleep);
- Safe
eval usage.