Monitor critical temperatures in Ubuntu Server
Posted: January 31st, 2014, 12:56 am
Hi all im new to this site and new to Linux as well i got the courage up to build a server Ubuntu 12.04 in RAID 1 and i have all that working perfect samba file shares as well only cant get plex working file permissions id say but that's another story
I followed the guide of how to send emails i got the email working fine i can send emails from the command line in Ubuntu putty and it works fine
My problem is i folled the other guide monitoring DriveTempShutdown and CPUTempShutdown but I'm really lost in terms of the script that u download to edit for these 2 files
DriveTempShutdown CPUTempShutdown
this one of the files that i edited
#!/bin/bash
# PURPOSE: Script to check temperature of installed hard drives and report/shutdown if specified temperatures exceeded
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com
# Expects three arguments:
# 1. Warning temperature
# 2. Critical shutdown temperature
# 3. If argument 3 is present then just check that drive letter
# eg. using ./DriveTemps.sh 35 45
# will warn when temperature of one or more drives reaches 35degrees and shutdown when any one of them hits 45
# eg. using ./DriveTemps.sh 35 45 c
# will warn when temperature of drive sdc reaches 35degrees and shutdown when it hits 45
# NOTES:
# Change the string ">>/home/htkh" as required
# Substitute string "scorpionvenomm@gmail.com" with your own email address in the string which starts "/usr/sbin/ssmtp scorpionvenomm@gmail.com"
# Change the command MyList='a b c d e' to the number of drives you have. In this case I'm using 2 drives
# Assumes /usr/sbin/smartctl -n standby -a /dev/sd$i returns the string 'Temperature_Celsius' somewhere
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'
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/mark/DriveWarning.Log
echo $(date) >>/home/mark/DriveWarning.Log
echo '' >>/home/mark/DriveWarning.Log
echo 'WARNING: TEMPERATURE FOR DRIVE sd'$i 'EXCEEDED' $1 '=>' $str2 >>/home/mark/DriveWarning.Log
echo '' >>/home/mark/DriveWarning.Log
echo '============================' >>/home/mark/DriveWarning.Log
fi
if [ ${str2} -ge $2 ]
then
echo '============================'
echo ''
echo 'CRITICAL: TEMPERATURE FOR DRIVE sd'$i 'EXCEEDED' $2 '=>' $str2
echo ''
echo '============================'
/sbin/shutdown -h now
/usr/sbin/ssmtp scorpionvenomm@gmail.com </home/mark/MyScripts/msg.txt
echo 'Email Sent.....'
exit
else
echo ' Temperature of Drive '$i' is OK at =>' $str2
echo ''
fi
fi
done
echo 'All Drives are within limits'
echo ''
this file here
/usr/sbin/ssmtp scorpionvenomm@gmail.com </home/mark/MyScripts/msg.txt
i created a folder called msg.tx in command line and put this in
To: scorpionvenomm@gmail.com
From: scorpionvenomm@gmail.com
Subject: alert
The critical CPU temperature has been reached. The server is shutting itself down!
is that correct ?
same with DriveWarning.log i created a folder as well so the log would go in there but i get emails giving me errors heres the email i get
/home/mark/MyScripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected
Mail Delivery Subsystem mailer-daemon@googlemail.com
12:00 AM (45 minutes ago)
to me
Delivery to the following recipient failed permanently:
mark@scorpionvenomm@gmail.com
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain gmail.com by gmail-smtp-in.l.google.com. [2a00400c:c00::1a].
The error that the other server returned was:
550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 http://support.google.com/mail/bin/answ ... nswer=6596 fu4si13610169wib.30 - gsmtp
----- Original message -----
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=message-idfrom:to:subject:content-type;
bh=a07dlHeTxfqnRdD/v7H3HqeLvyv2sdFRdFp/O7VKD6w=;
b=nxY5fLjlgt8thNkBMKTLiQNhhjkZBIbQnN2hmuM/aYWAeGvgyNwsRZfKDBlk5i/cmW
x7YrYCY1XVzMq4iho5p2svdu7X8WMUxWygnvY177hKSkAvFjypkfOjcUFOQ4Oam/zhYG
eY3yKOuaE2R8Fhzv0Q28vQW6pFU9xDFVcfeZEZPbmclf23alr/hBUd8sLzdnAEIlb77u
QX/hxbKNlip2PAFupFYgwhm9USgHI9zLdbW/1ogfGAuyUW9Ts1gqV0RYm8vy3AwHsxsR
nMST1KeOKRcC4pHa0FUbKK7T68L6gBAtiW8QWqBagV5b5OxZ8SCYofPgDXowsCs7Fy1U
j81w==
X-Received: by 10.180.91.17 with SMTP id ca17mr25654551wib.41.1391126403852;
Thu, 30 Jan 2014 16:00:03 -0800 (PST)
Return-Path: <scorpionvenomm@gmail.com>
Received: from scorpionvenomm@gmail.com ([])
by mx.google.com with ESMTPSA id fb8sm28796181wic.3.2014.01.30.16.00.02
for <mark@scorpionvenomm@gmail.com>
(version=TLSv1 cipher=RC4-SHA bits=128/128);
Thu, 30 Jan 2014 16:00:03 -0800 (PST)
Message-ID: <52eae783.68b9b40a.0d74.ffffb633@mx.google.com>
Received: by scorpionvenomm@gmail.com (sSMTP sendmail emulation); Fri, 31 Jan 2014 00:00:01 +0000
Date: Fri, 31 Jan 2014 00:00:01 +0000
From: root <scorpionvenomm@gmail.com>
To: mark
Subject: Cron <mark@scorpionvenomm> /home/mark/MyScripts/CPUTempShutdown.sh 35 45 >/dev/null
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/mark>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=mark>
Sorry about the long message just thought id show it all and somebody might be able to help me i would really appreciate that
thanks
I followed the guide of how to send emails i got the email working fine i can send emails from the command line in Ubuntu putty and it works fine
My problem is i folled the other guide monitoring DriveTempShutdown and CPUTempShutdown but I'm really lost in terms of the script that u download to edit for these 2 files
DriveTempShutdown CPUTempShutdown
this one of the files that i edited
#!/bin/bash
# PURPOSE: Script to check temperature of installed hard drives and report/shutdown if specified temperatures exceeded
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com
# Expects three arguments:
# 1. Warning temperature
# 2. Critical shutdown temperature
# 3. If argument 3 is present then just check that drive letter
# eg. using ./DriveTemps.sh 35 45
# will warn when temperature of one or more drives reaches 35degrees and shutdown when any one of them hits 45
# eg. using ./DriveTemps.sh 35 45 c
# will warn when temperature of drive sdc reaches 35degrees and shutdown when it hits 45
# NOTES:
# Change the string ">>/home/htkh" as required
# Substitute string "scorpionvenomm@gmail.com" with your own email address in the string which starts "/usr/sbin/ssmtp scorpionvenomm@gmail.com"
# Change the command MyList='a b c d e' to the number of drives you have. In this case I'm using 2 drives
# Assumes /usr/sbin/smartctl -n standby -a /dev/sd$i returns the string 'Temperature_Celsius' somewhere
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'
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/mark/DriveWarning.Log
echo $(date) >>/home/mark/DriveWarning.Log
echo '' >>/home/mark/DriveWarning.Log
echo 'WARNING: TEMPERATURE FOR DRIVE sd'$i 'EXCEEDED' $1 '=>' $str2 >>/home/mark/DriveWarning.Log
echo '' >>/home/mark/DriveWarning.Log
echo '============================' >>/home/mark/DriveWarning.Log
fi
if [ ${str2} -ge $2 ]
then
echo '============================'
echo ''
echo 'CRITICAL: TEMPERATURE FOR DRIVE sd'$i 'EXCEEDED' $2 '=>' $str2
echo ''
echo '============================'
/sbin/shutdown -h now
/usr/sbin/ssmtp scorpionvenomm@gmail.com </home/mark/MyScripts/msg.txt
echo 'Email Sent.....'
exit
else
echo ' Temperature of Drive '$i' is OK at =>' $str2
echo ''
fi
fi
done
echo 'All Drives are within limits'
echo ''
this file here
/usr/sbin/ssmtp scorpionvenomm@gmail.com </home/mark/MyScripts/msg.txt
i created a folder called msg.tx in command line and put this in
To: scorpionvenomm@gmail.com
From: scorpionvenomm@gmail.com
Subject: alert
The critical CPU temperature has been reached. The server is shutting itself down!
is that correct ?
same with DriveWarning.log i created a folder as well so the log would go in there but i get emails giving me errors heres the email i get
/home/mark/MyScripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 49: [: -ge: unary operator expected
/home/mark/MyScripts/CPUTempShutdown.sh: line 59: [: -ge: unary operator expected
Mail Delivery Subsystem mailer-daemon@googlemail.com
12:00 AM (45 minutes ago)
to me
Delivery to the following recipient failed permanently:
mark@scorpionvenomm@gmail.com
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain gmail.com by gmail-smtp-in.l.google.com. [2a00400c:c00::1a].
The error that the other server returned was:
550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 http://support.google.com/mail/bin/answ ... nswer=6596 fu4si13610169wib.30 - gsmtp
----- Original message -----
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=message-idfrom:to:subject:content-type;
bh=a07dlHeTxfqnRdD/v7H3HqeLvyv2sdFRdFp/O7VKD6w=;
b=nxY5fLjlgt8thNkBMKTLiQNhhjkZBIbQnN2hmuM/aYWAeGvgyNwsRZfKDBlk5i/cmW
x7YrYCY1XVzMq4iho5p2svdu7X8WMUxWygnvY177hKSkAvFjypkfOjcUFOQ4Oam/zhYG
eY3yKOuaE2R8Fhzv0Q28vQW6pFU9xDFVcfeZEZPbmclf23alr/hBUd8sLzdnAEIlb77u
QX/hxbKNlip2PAFupFYgwhm9USgHI9zLdbW/1ogfGAuyUW9Ts1gqV0RYm8vy3AwHsxsR
nMST1KeOKRcC4pHa0FUbKK7T68L6gBAtiW8QWqBagV5b5OxZ8SCYofPgDXowsCs7Fy1U
j81w==
X-Received: by 10.180.91.17 with SMTP id ca17mr25654551wib.41.1391126403852;
Thu, 30 Jan 2014 16:00:03 -0800 (PST)
Return-Path: <scorpionvenomm@gmail.com>
Received: from scorpionvenomm@gmail.com ([])
by mx.google.com with ESMTPSA id fb8sm28796181wic.3.2014.01.30.16.00.02
for <mark@scorpionvenomm@gmail.com>
(version=TLSv1 cipher=RC4-SHA bits=128/128);
Thu, 30 Jan 2014 16:00:03 -0800 (PST)
Message-ID: <52eae783.68b9b40a.0d74.ffffb633@mx.google.com>
Received: by scorpionvenomm@gmail.com (sSMTP sendmail emulation); Fri, 31 Jan 2014 00:00:01 +0000
Date: Fri, 31 Jan 2014 00:00:01 +0000
From: root <scorpionvenomm@gmail.com>
To: mark
Subject: Cron <mark@scorpionvenomm> /home/mark/MyScripts/CPUTempShutdown.sh 35 45 >/dev/null
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/mark>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=mark>
Sorry about the long message just thought id show it all and somebody might be able to help me i would really appreciate that
thanks