#!/bin/sh
#
# Code by MauriziON
#
# This software is released without any warranty and the author
# is not responsable for any problem.
#

hdparm -S 5 -M 128 /dev/sda2
maxtemp=55
range=5
mintemp=`expr $maxtemp - $range`
echo "-Max temp set to $maxtemp c and range set to $range c mintemp is set to $mintemp c"

while true
do
hddstatus=`hdparm -C /dev/sda2 | grep "drive state" | cut -c19-25`

	if [ $hddstatus = "standby"  ]
	then
		/usr/bin/front_ioctl --job fanoff
		echo "-drive in standby -fanoff "
	else
	temphdd=`hddtemp -n -u=C -q /dev/sda2`

		if [ $temphdd -ge $maxtemp  ]
		then
			/usr/bin/front_ioctl --job fanon
			echo "-max temp $temphdd reached -fanon "
			#more sleep ?
		else
			if [ $temphdd -le  $mintemp ]; then
				/usr/bin/front_ioctl --job fanoff
				echo "-min temp $temphdd reached -fanoff "
			fi
		fi
	fi
	sleep 30
done
