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

dpoper1Asked:
Who is Participating?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.