The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Export Variable navi Shell Programming and Scripting 2 06-10-2008 03:39 AM
Export variable as number zeus101 Shell Programming and Scripting 2 10-15-2007 09:09 PM
export variable. its-ashish UNIX for Dummies Questions & Answers 5 02-20-2007 03:24 AM
Export command giving Variable Name vs the Value set for the Variable ParNone UNIX for Dummies Questions & Answers 2 04-03-2006 08:43 AM
Syntax to export any variable malaymaru Shell Programming and Scripting 5 05-17-2005 01:16 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-25-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Export system temperature to variable

I have a Korn shell that successfully queries the system temperature of my server. I am able to use the envmon env_current_temp to display just the last 2 characters of output. The full output is:
envmon:
env_current_temp = 36

I tried writing the value (36) out to txt, then reading the txt file as a variable, but I am stuck.

If I hardcode curt=36 then it works fine, so I think it is just a matter of getting the 2 last characters into a numeric variable.

#! /bin/ksh
echo Temperature
/sbin/sysconfig -q envmon env_current_temp | cut -b20-21
echo $curt
#fdeg=$(echo "scale=2; ($curt*9/5) +32" | bc -l)
#kdeg=$(echo "scale=2; ($curt+273.15)" | bc -l)
#echo "$curt Celsius $fdeg Fahrenheit $kdeg Kelvin"

Any help would be greatly appreciated.
Reply With Quote
Forum Sponsor
  #2  
Old 07-25-2008
Registered User
 

Join Date: May 2008
Location: s'pore
Posts: 916
grep -v '= *$' <textfile>
Reply With Quote
  #3  
Old 07-26-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Assuming your ksh is ksh93
Code:
curt=$(/sbin/sysconfig -q envmon env_current_temp)
curt=${curt: -2}
Reply With Quote
  #4  
Old 07-29-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Smile Resolved temperature in Unix servers.

That worked, thank you both!

I found perhaps a more streamlined approach than before.
Here is the final code. Using rsh, I also grabbed the temperatures of the other Unix servers in the room.

Thanks again for the help, it really pointed me in the right direction!

#! /bin/ksh
clear
echo
echo Current Server2 Temperature:
curt2=$(rsh -l mfg Server2 /sbin/sysconfig -q envmon env_current_temp |grep -v envmon |cut -b20-21)
fdeg2=$(echo "scale=2; ($curt2*9/5) +32" | bc -l)
kdeg2=$(echo "scale=2; ($curt2+273.15)" | bc -l)
echo "$curt2 Celsius $fdeg2 Fahrenheit $kdeg2 Kelvin"
echo
echo Current Server7 Temperature:
curt7=$(rsh -l mfg Server7 /sbin/sysconfig -q envmon env_current_temp |grep -v envmon |cut -b20-21)
fdeg7=$(echo "scale=2; ($curt7*9/5) +32" | bc -l)
kdeg7=$(echo "scale=2; ($curt7+273.15)" | bc -l)
echo "$curt7 Celsius $fdeg7 Fahrenheit $kdeg7 Kelvin"
echo
echo Current Server8 Temperature:
curt8=$(rsh -l mfg Server8 /sbin/sysconfig -q envmon env_current_temp |grep -v envmon |cut -b20-21)
fdeg8=$(echo "scale=2; ($curt8*9/5) +32" | bc -l)
kdeg8=$(echo "scale=2; ($curt8+273.15)" | bc -l)
echo "$curt8 Celsius $fdeg8 Fahrenheit $kdeg8 Kelvin"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0