Monitor critical temperatures in Ubuntu Server

scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

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. [2a00:1450:400c: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-id:date:from: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
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Monitor critical temperatures in Ubuntu Server

Post by Ian »

Hi,

The problem is because you have to edit the CPUTempShutdown.sh script to match the output from your CPU. Try calling the script from the command line and you'll see the "[: -ge: unary operator expected" error.

If you need help with that just shout! :thumbup:

Ian.
scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Re: Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

ok cool how do you do that sorry im new to linux ive been at this all day yesterday up till 2 am trying to figure out and back at it now :(


im looking at that error and ive gone back to the CPUTempShutdown.sh file and it says line 49 line 59 line 49 and line 49 thats the if statement i would not know how to fix that hopefully you can help me i would really appreciate that :)
scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Re: Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

hi just wondering does anyone know how to fix that script for me i would be really grateful as i keep getting emails every hour on the errors thanks
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Monitor critical temperatures in Ubuntu Server

Post by Ian »

Hi,

Sorry for the delay. That script is not currently monitoring your CPU temps so it might be an idea to disable it until you've got it working.

Please issue the following command in a Terminal and send me the output in your next post:

Code: Select all

sensors
Thanks,

Ian.
scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Re: Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

hey how are you thanks for getting back to me :) heres the code for sensors

Code: Select all

Last login: Sat Feb  1 19:46:08 2014 from 192.168.2.213
mark@scorpionvenomm:~$ sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8°C  (crit = +86.0°C)
temp2:        +29.8°C  (crit = +86.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +34.0°C  (high = +80.0°C, crit = +85.0°C)
Core 0:         +24.0°C  (high = +80.0°C, crit = +85.0°C)
Core 1:         +26.0°C  (high = +80.0°C, crit = +85.0°C)

mark@scorpionvenomm:~$ 
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Monitor critical temperatures in Ubuntu Server

Post by Ian »

Hi,

Change the line in the script which currently reads

Code: Select all

newstr=${str:14:2}
to

Code: Select all

newstr=${str:17:2}
If I've got that right it should pull out that your CPU cores are running at 24 and 26 respectively. If not, let me know.

Ian.
scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Re: Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

ok cool ive done that and heres the code thanks

Code: Select all

root@scorpionvenomm:~# sensors
acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8°C  (crit = +86.0°C)
temp2:        +29.8°C  (crit = +86.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +34.0°C  (high = +80.0°C, crit = +85.0°C)
Core 0:         +24.0°C  (high = +80.0°C, crit = +85.0°C)
Core 1:         +26.0°C  (high = +80.0°C, crit = +85.0°C)

root@scorpionvenomm:~# 
User avatar
Ian
Moderator
Posts: 752
Joined: January 1st, 2011, 7:00 am

Re: Monitor critical temperatures in Ubuntu Server

Post by Ian »

What happens if you now run the script via the command line? Do you want to send me the output in your next post for me to have a look?

Thanks,

Ian.
scorpionvenomm
Member
Member
Posts: 11
Joined: January 31st, 2014, 12:14 am

Re: Monitor critical temperatures in Ubuntu Server

Post by scorpionvenomm »

is this what ur looking for ./CPUTempShutdown.sh 35 50 thats the ouptut when i do that

Code: Select all

root@scorpionvenomm:/home/mark/MyScripts# ./CPUTempShutdown.sh 35 50
JOB RUN AT Sun Feb  2 00:06:49 GMT 2014
=======================================

CPU Warning Limit set to => 35
CPU Shutdown Limit set to => 50


acpitz-virtual-0
Adapter: Virtual device
temp1:        +27.8°C  (crit = +86.0°C)
temp2:        +29.8°C  (crit = +86.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +33.0°C  (high = +80.0°C, crit = +85.0°C)
Core 0:         +25.0°C  (high = +80.0°C, crit = +85.0°C)
Core 1:         +27.0°C  (high = +80.0°C, crit = +85.0°C)



 Temperature Core 0 OK at => 25

 Temperature Core 1 OK at => 27

Both CPU Cores are within limits

root@scorpionvenomm:/home/mark/MyScripts# 
Post Reply