HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   ISPConfig 3 Priority Support (http://www.howtoforge.com/forums/forumdisplay.php?f=35)
-   -   ISPconfig3 - Ubuntu 12.04.2 - ShellScript issues -> LMsensors (http://www.howtoforge.com/forums/showthread.php?t=62116)

danhansen@denmark 6th June 2013 17:49

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]

till 7th June 2013 10:33

Normally you would use the sendmail compatibility binary on a postfix server to send mails from a shell script. So the command to send mail is:

/usr/sbin/sendmail

and not:

/usr/sbin/ssmtp

danhansen@denmark 7th June 2013 11:10

Hi,

thanks for your reply. I will try that..


All times are GMT +2. The time now is 14:23.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.