#!/usr/local/bin/perl # This script works on SuperMicro X9 and X10 motherboards to control case # fan speed mode in response to hard drive temperatures. # It should be set as a cron job to run on roughly a three minute interval. # edit the following values $number_of_hard_drives = 5; $hd_designator = "/dev/da"; $min_fan_speed = 400; $max_fan_speed = 1500; $LogFile = '/root/HD_TempLog.txt'; $min_fan_speed *= 1.3; $max_fan_speed *= 0.8; # edit nothing below this line use POSIX qw(strftime); $datestring = strftime "%F %H:%M:%S", localtime; open (LOGFILE, ">>$LogFile"); $max_temp = 0; foreach $item (0..$number_of_hard_drives-1) { $command = "/usr/local/sbin/smartctl -A $hd_designator$item | grep Temp"; # print "$command\n"; $output = `$command`; @vals = split(" ", $output); # grab last item from the output, which is the hard drive temperature $temp = "$vals[-1]\n"; # update maximum drive temperature $max_temp = $temp if $temp > $max_temp; } if ($max_temp > 39) { # at least one hard drive is 40 deg C or higher # set fan speed control to Full `ipmitool raw 0x30 0x45 0x01 0x01` } elsif ($max_temp == 39 ){ # maximum drive temperature is 39 deg C # set fan speed to 50% duty cycle `ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x32` # set fan speed to Standard # `ipmitool raw 0x30 0x45 0x01 0x00` } else { # all hard drive temperatures are 38 deg C or cooler # set fan speed control to Optimal `ipmitool raw 0x30 0x45 0x01 0x02` } # reset BMC if temps are cool, and fan is not slow if ($max_temp < 38){ $command = "ipmitool sdr | grep FAN2"; $output = `$command`; @vals = split(" ", $output); $fan_speed = "$vals[2]"; if ($fan_speed > $min_fan_speed){ `ipmitool bmc reset cold`; } } # reset BMC if temps are warm, and fan is not fast if ($max_temp > 40){ $command = "ipmitool sdr | grep FAN2"; $output = `$command`; @vals = split(" ", $output); $fan_speed = "$vals[2]"; if ($fan_speed < $max_fan_speed){ `ipmitool bmc reset cold`; } } print LOGFILE "$datestring - $max_temp"; close (LOGFILE);
The raw commands to set fan speed are commanding a duty cycle - 100% duty cycle would be full speed. Thus that portion of the script should work for any PWM fan. I recently added a section to check for a stuck fan speed by checking to see if the fan speed is abnormally low or high given a hot or cold disk. This portion uses max and min fan speed constants that the user must set at the start of the script.Hey Kevin, this thread really has my attention but I'm a little new to scripting. I'm in desperate need of some fan control though, so I'm willing to try some things. My hottest hard drive temperatures are hitting the 50c when running at Optimal Speeds, which isn't going to cut it. At full speed, I hit around 36. I have a few questions though.
Does your script take into account the max RPMs of the specific fan or is it a hard coded RPM? I have the Noctua NF-F12 iPPC 3000 PWM that I would like to run at half speed for the medium to slow range. Is this easily adjustable?
Yes, that command should command 50% duty cycle, which would be very roughly half speed.I haven't tried it yet (as this is production) but can I run the following command to set all fans to 50%?
ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x32
The raw commands to set fan speed are commanding a duty cycle - 100% duty cycle would be full speed. Thus that portion of the script should work for any PWM fan. I recently added a section to check for a stuck fan speed by checking to see if the fan speed is abnormally low or high given a hot or cold disk. This portion uses max and min fan speed constants that the user must set at the start of the script.
What motherboard do you have?
I'm spending most of today trapped in an airliner, so I won't be back on the forum for quite a few hours.
not foundl.sh: : not foundl.sh: : not foundl.sh: ./fancontrol.sh: =: not found : not foundl.sh: ./fancontrol.sh: =: not found : not foundl.sh: ./fancontrol.sh: =: not found : not foundl.sh: ./fancontrol.sh: =: not found : not foundl.sh: : not foundl.sh: ./fancontrol.sh: =: not found : not foundl.sh: ./fancontrol.sh: *=: not found : not foundl.sh: ./fancontrol.sh: *=: not found : not foundl.sh: : not foundl.sh: : not foundl.sh: ./fancontrol.sh: 20: Syntax error: "(" unexpected
What exactly is the statement in the cron job? You can't say ./fancontrol.sh, because it will look in the wrong place. You should give the full path to its location.I have placed the script in one of my volumes . . .
I have "/mnt/volumename/scripts/fancontrol.sh" in there.What exactly is the statement in the cron job? You can't say ./fancontrol.sh, because it will look in the wrong place. You should give the full path to its location.
Is it set to be executable?
Same thing.Yes, that's it. I'm not sure what those errors mean, other than a problem in line 20. What happens when you try to run the script manually, being in its directory and typing ./scriptname.sh?
#!/usr/local/bin/perl # This script works on SuperMicro X9 and X10 motherboards to control case # fan speed mode in response to hard drive temperatures. # It should be set as a cron job to run on roughly a three minute interval. # edit the following values $number_of_hard_drives = 24; $hd_designator = "/dev/da"; $min_fan_speed = 1200; $max_fan_speed = 2500; $LogFile = '/root/HD_TempLog.txt'; $min_fan_speed *= 1.3; $max_fan_speed *= 0.8; # edit nothing below this line
Which version of FreeNAS are you using?I apologize in advanced but I'm having some trouble getting the script to work. I have placed the script in one of my volumes and given it 'Everyone" access to hopefully alleviate the permissions issue. I am trying to run the cronjob as root and getting the following error message:
Which version of FreeNAS are you using?
Please show the full version of your script, including line 20.
The output of cat -e the_script.sh would be useful to see if there's isn't any weird characters :)
#!/usr/local/bin/perl$ $ # This script works on SuperMicro X9 and X10 motherboards to control case$ # fan speed mode in response to hard drive temperatures.$ # It should be set as a cron job to run on roughly a three minute interval.$ $ # edit the following values$ $number_of_hard_drives = 24;$ $hd_designator = "/dev/da";$ $min_fan_speed = 1200;$ $max_fan_speed = 1800;$ $ $LogFile = '/root/HD_TempLog.txt';$ $min_fan_speed *= 1.3;$ $max_fan_speed *= 0.8;$ $ # edit nothing below this line$ $ use POSIX qw(strftime);$ $datestring = strftime "%F %H:%M:%S", localtime;$ $ open (LOGFILE, ">>$LogFile");$ $ $max_temp = 0;$ $ foreach $item (0..$number_of_hard_drives-1) {$ $command = "/usr/local/sbin/smartctl -A $hd_designator$item | grep Temp";$ $ # print "$command\n";$ $ $output = `$command`;$ @vals = split(" ", $output);$ $ # grab last item from the output, which is the hard drive temperature$ $temp = "$vals[-1]\n";$ $ # update maximum drive temperature$ $max_temp = $temp if $temp > $max_temp;$ }$ $ if ($max_temp > 39) {$ # at least one hard drive is 40 deg C or higher$ # set fan speed control to Full$ `ipmitool raw 0x30 0x45 0x01 0x01`$ }$ $ elsif ($max_temp == 39 ){$ # maximum drive temperature is 39 deg C$ # set fan speed to 50% duty cycle$ `ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x32`$ # set fan speed to Standard$ # `ipmitool raw 0x30 0x45 0x01 0x00`$ }$ $ else {$ # all hard drive temperatures are 38 deg C or cooler$ # set fan speed control to Optimal$ `ipmitool raw 0x30 0x45 0x01 0x02`$ }$ $ # reset BMC if temps are cool, and fan is not slow$ if ($max_temp < 38){$ $command = "ipmitool sdr | grep FAN2";$ $output = `$command`;$ @vals = split(" ", $output);$ $fan_speed = "$vals[2]";$ $ if ($fan_speed > $min_fan_speed){$ `ipmitool bmc reset cold`;$ }$ }$ $ # reset BMC if temps are warm, and fan is not fast$ if ($max_temp > 40){$ $command = "ipmitool sdr | grep FAN2";$ $output = `$command`;$ @vals = split(" ", $output);$ $fan_speed = "$vals[2]";$ $ if ($fan_speed < $max_fan_speed){$ `ipmitool bmc reset cold`;$ }$ }$ $ print LOGFILE "$datestring - $max_temp";$ close (LOGFILE);$ $