Problems with cron table

thebigbaddie
Member
Member
Posts: 9
Joined: July 16th, 2013, 8:31 pm

Re: Problems with cron table

Post by thebigbaddie »

Okay so my issue with the drive script is that it shuts down the server after detecting the first HDD over the critical temperature. While that is nice I would rather know any and all HDDs over critical so I can adjust what is needed to fix the issue for the entirety of the server not just that individual drive. Specifically my issue is that if a critical temp is tripped then only drives tested until that critical temperature are logged/emailed. Here is the script as of now.

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
ricksebak
Member
Member
Posts: 33
Joined: February 10th, 2013, 9:34 pm

Re: Problems with cron table

Post by ricksebak »

So basicly you want to make sure that you test all of the drives and send all of the necessary emails before you shut down? In that case, prior to your for loop, i would "cp /dev/null /tmp/somefile" to make sure that /tmp/somefile is empty. Then inside the loop where you have your shutdown command, I would remove the shutdown command and replace it with "echo 1 > /tmp/somefile." No matter how many times the loop detected a hot drive, that file will still be the same when the loop is done. So then after the loop, you can check the contents or the size of /tmp/somefile, and if it contains 1 or if it's not empty, shutdown the computer.
Post Reply