View Single Post
  #1  
Old 6th June 2013, 16:49
danhansen@denmark danhansen@denmark is offline
HowtoForge Supporter
 
Join Date: Mar 2013
Posts: 187
Thanks: 39
Thanked 4 Times in 4 Posts
Exclamation ISPconfig3 - Ubuntu 12.04.2 - ShellScript issues -> LMsensors

Hi,

Creating Shell Script
Cron-Job
Application: LMsensors

Shell Script funktions:
1. If CPU hot'er than X then sendmail and log
2. If CPU hot'er than Y then sendmail, log and shutdown

Problems:
1. Script works regarding log'ing and shut'ing down - but I'm having trouble getting the script to sendmail (and to put text into the mail/sending msg.txt)


LMsensors Print - Command "sensors"

root@server1:/home/user# sensors
it8712-isa-0290
Adapter: ISA adapter
in0: +1.52 V (min = +0.00 V, max = +4.08 V)
in1: +1.47 V (min = +0.00 V, max = +4.08 V)
in2: +3.30 V (min = +0.00 V, max = +4.08 V)
in3: +3.01 V (min = +0.00 V, max = +4.08 V)
in4: +3.06 V (min = +0.00 V, max = +4.08 V)
in5: +2.30 V (min = +0.00 V, max = +4.08 V)
in6: +1.36 V (min = +0.00 V, max = +4.08 V)
in7: +3.04 V (min = +0.00 V, max = +4.08 V)
Vbat: +4.08 V
fan1: 7670 RPM (min = 0 RPM, div = 8)
fan3: 0 RPM (min = 0 RPM, div = 8)
temp1: +25.0C (low = +127.0C, high = +127.0C) sensor = thermistor
temp2: -12.0C (low = +127.0C, high = +127.0C) sensor = thermistor
temp3: +44.0C (low = +127.0C, high = +127.0C) sensor = thermal diode
cpu0_vid: +1.525 V
intrusion0: ALARM


Running Script and setting variables $1 and $2 using the line command: ./CPUTempShutdown.sh 30 60

[BEGIN SCRIPT]

echo "JOB RUN AT $(date)"
echo "============================================= "

echo ''
echo 'CPU Warning Limit set to => '$1
echo 'CPU Shutdown Limit set to => '$2
echo ''
echo ''

sensors

echo ''
echo ''

str=$(sensors | grep "temp1:")
newstr=${str:15:2}

if [ ${newstr} -ge $1 ] # LOG'GING WORKS JUST FINE. NEED TO MAIL AS WELL USING SENDMAIL
then
echo '============================================' >>/home/user/MonitorHardware/CPUWarning.Log
echo $(date) >>/home/user/MonitorHardware/CPUWarning.Log
echo '' >>/home/user/MonitorHardware/CPUWarning.Log
echo ' WARNING: TEMPERATURE CORE EXCEEDED' $1 '=>' $newstr >>/home/user/MonitorHardware/CPUWarning.Log
echo '' >>/home/user/MonitorHardware/CPUWarning.Log
echo '============================================' >>/home/user/MonitorHardware/CPUWarning.Log
fi

if [ ${newstr} -ge $2 ] # SHUTDOWN WORKS JUST FINE. NEED TO LOG AND MAIL AS WELL USING SENDMAIL
then
echo '============================================'
echo ''
echo 'CRITICAL: TEMPERATURE CORE EXCEEDED' $2 '=>' $newstr
echo ''
echo '============================================'
/sbin/shutdown -h now
/usr/sbin/ssmtp warning@domain.tld </home/user/MyScripts/HotCPU.txt
echo 'Email Sent.....'
exit
else
echo ' Temperature temp1 OK at =>' $newstr
echo ''
fi

echo 'CPU Core is within limits'
echo ''

[END SCRIPT]
__________________
Kind Regards
Dan

__________________________________________________ _______
Fixed IP/WAN
DMZ -> "ispserverip"
Primary NameServer -> ns1.myprimarynameserver.tld
Secondary NameServer -> ns2.somedomainservice.tld

Ubuntu Server 12.04.4
ISPconfig 3 v.3.0.5.2 (Single Server Setup)
NameServer: BIND v.9.8.1-P1
SquirrelMail: v.1.4.22
MailServer: PostFix v.2.9.6 - IMAP/POP3 Dovecot v.2.0.19
Database: MySQL Server v.5.5.29-0ubuntu0.12.04.2
Tutorial: "ThePerfectServer-ISPconfig3-Ubuntu12.04"

Last edited by danhansen@denmark; 6th June 2013 at 16:53.
Reply With Quote
Sponsored Links