#!/bin/bash
SENSORNAME1="Inlet"
SENSORNAME2="0Eh"
SENSORNAME3="0Fh"


TEMPTHRESHOLD="29"
STATICFANSPEED="0x05"

T=$(ipmitool sdr type temperature | grep $SENSORNAME1 | cut -d"|" -f5 | cut -d" " -f2)
T2=$(ipmitool sdr type temperature | grep $SENSORNAME2 | cut -d"|" -f5 | cut -d" " -f2)
T3=$(ipmitool sdr type temperature | grep $SENSORNAME3 | cut -d"|" -f5 | cut -d" " -f2)

echo "    "
echo "    "
echo "    "

echo "$SENSORNAME1 Temp:  $T"
echo "CPU $SENSORNAME2 Temp:  $T2"
echo "CPU $SENSORNAME3 Temp:  $T3"

if [[ $T > $TEMPTHRESHOLD ]]
	then 
		echo "--> enabling dynamic fan control..."
    		ipmitool raw 0x30 0x30 0x01 0x01
      	else
		echo "--> disabling dynamic fan control..."
		ipmitool raw 0x30 0x30 0x01 0x00
		echo "--> setting static fan speed... $STATICFANSPEED"
		ipmitool raw 0x30 0x30 0x02 0xff $STATICFANSPEED
fi

