• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 371
  • Last Modified:

script to monitor cpu temperatures

Hi, I need assistance on the script below in order to get an email every time that the system temperature is above the threashold. The error I keep on getting is on line 2, the exact error is

./sensors1.sh: line 3: Temp: command not found


Thank you in advance for your assistance.

regards,

michael
#!/bin/bash
LIMIT="30"
CPU1TEMP="ipmi-sensors | grep "CPU Temp 1" | cut -c 30-31"
 
if [ "$CPU1TEMP" > "$LIMIT" ]
then
   echo "Threashold = ${LIMIT}"
   echo "CPU1 Temp = ${CPU1TEMP}"
   mail -s "CPU over upper limit $CPU1TEMP current temperature" myemail@gmail.com
fi

Open in new window

0
dpoper1
Asked:
dpoper1
  • 2
  • 2
1 Solution
 
TintinCommented:
Your script should be:
#!/bin/bash
LIMIT=30
CPU1TEMP=$(ipmi-sensors | grep "CPU Temp 1" | cut -c 30-31)
 
if [ "$CPU1TEMP" -gt "$LIMIT" ]
then
   echo "Threshold = $LIMIT"
   echo "CPU1 Temp = $CPU1TEMP"
   echo | mail -s "CPU over upper limit $CPU1TEMP current temperature" myemail@gmail.com
fi

Open in new window

0
 
dpoper1Author Commented:
Quick question for you how would I be able to convert the result to a Fahrenheit value, the formula is the following: (5/9)*(Tf-32).

Thank you.

regards,

Michael
0
 
dpoper1Author Commented:
Please take a look at the code below, I would like to have a single script that will go against different CPU temperatures.

Michael

#!/bin/bash
LIMIT="30"
CPU1TEMP=$(ipmi-sensors | grep "CPU Temp 1" | cut -c 30-31)
CPU2TEMP=$(ipmi-sensors | grep "CPU Temp 2" | cut -c 30-31)
 
 
if [ "$CPU1TEMP" -gt "$LIMIT" ]
then
   echo "Threashold = (5/9)*($LIMIT -32) " >> /tmp/tempcpu1
   echo "CPU1 Temp = $CPU1TEMP" >> /tmp/tempcpu1
   mail -s "CPU over upper limit $CPU1TEMP current temperature" myemail@gmail.com </tm
p/tempcpu1
   rm -f /tmp/tempcpu1
fi
 
if [ "$CPU2TEMP" -gt "$LIMIT" ]
then
   echo "Threashold = $LIMIT" >> /tmp/tempcpu2
   echo "CPU2 Temp = $CPU22EMP" >> /tmp/tempcpu2
   mail -s "CPU over upper limit $CPU1TEMP current temperature" myemail@gmail.com </tm
p/tempcpu2
   rm -f /tmp/tempcpu2
fi

Open in new window

0
 
TintinCommented:

#!/bin/bash
LIMIT=30
TEMP=/tmp/cpu$$
 
for cpu in 1 2
do
  CPUTEMP=$(ipmi-sensors | grep "CPU Temp $cpu" | cut -c 30-31)
 
  if [ $CPUTEMP -gt $LIMIT ]
  then
     tf=$(echo "scale=2;(5/9)*($LIMIT -32)"|bc)
     cf=$(echo "scale=2;(5/9)*($CPUTEMP -32)"|bc)
     echo "Threshold = ${tf}f" >$TEMP
     echo "CPU$cput Temp = ${cf}f" >>$TEMP
     mail -s "CPU over upper limit $CPUTEMP current temperature" myemail@gmail.com <$TEMP
     rm -f $TEMP
  fi
done

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now