Code: Select all
echo "JOB RUN AT $(date)"
echo '============================'
echo ''
echo 'Drive Warning Limit set to =>' $1
echo 'Drive Shutdown Limit set to =>' $2
echo ''
echo ''
if [ $# -eq 2 ]
then
MyList='a b c d e f'
echo 'Testing all drives'
else
MyList=($3)
echo 'Testing only the system drive'
fi
echo ''
for i in $MyList
do
echo 'Drive /dev/sd'$i
/usr/sbin/smartctl -n standby -a /dev/sd$i | grep Temperature_Celsius
done
echo ''
echo ''
for i in $MyList
do
#Check state of drive 'active/idle' or 'standby'
stra=$(/sbin/hdparm -C /dev/sd$i | grep 'drive' | awk '{print $4}')
echo 'Testing Drive sd'$i
if [ ${stra} = 'standby' ]
then
echo ' Drive sd'$i 'is in standby'
echo ''
else
str1='/usr/sbin/smartctl -n standby -a /dev/sd'$i
str2=$($str1 | grep Temperature_Celsius | awk '{print $10}')
if [ ${str2} -ge $1 ]
then
echo '============================' >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
echo $(date) >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
echo '' >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
echo 'WARNING: Temperature for drive sd'$i ' exceeded ' $1 ' => ' $str2 >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
echo '' >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
echo '============================' >>/home/thebigbaddie/Documents/HDDTempLogs/DriveWarning`date +%F`.Log
fi
if [ ${str2} -ge $2 ]
then
echo '============================' >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo $(date) >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo '' >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo 'CRITICAL: Temperature for drive sd'$i ' exceeded ' $2 ' => ' $str2 >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo '' >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo '============================' >>/home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
echo 'Email Sent.....'
/usr/sbin/ssmtp dylan.server244@gmail.com </home/thebigbaddie/Documents/HDDTempLogMsgs/msg`date +%F`.txt
#/sbin/shutdown -h now
exit
else
echo ' Temperature of Drive '$i' is OK at =>' $str2
echo ''
fi
fi
done