Export system temperature to variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Export system temperature to variable
# 1  
Old 07-25-2008
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.
# 2  
Old 07-26-2008
grep -v '= *$' <textfile>
# 3  
Old 07-26-2008
Assuming your ksh is ksh93
Code:
curt=$(/sbin/sysconfig -q envmon env_current_temp)
curt=${curt: -2}

# 4  
Old 07-29-2008
Bug 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"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help export variable

Hi, Please find my code below. ps -xef | grep 14766 | awk 'BEGIN{X="java_home=";X="weblogic_home="} {for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P?P:$i;print X""s}}}' echo "java_home="$java_home echo "weblogic_home="$weblogic_home Output: Why does... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Can't export variable

I am relatively new to exporting variables, and I just can't seem to make this count work. What I have is the following: TOTAL=$($IMAGELIST -backupid $IM -U |gawk '{print $5}' |tail -1)|gawk '{print $6}' RESTORED=$($BPDBJOBS -most_columns -jobid $JOBS |cut -f15 -d,) |gawk '{print $6}' export... (7 Replies)
Discussion started by: newbie2010
7 Replies

3. Shell Programming and Scripting

help t export the variable from a particular file

Hello Guys, I need you help to do one task I have script which is actually doing to fetch the code of any repository in svn for e.g.:- I can use svn to checkout the repository but I want to checkout the repository for particular tag like svn co <url>/svn/repo/<tag-name> and this... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

4. Shell Programming and Scripting

where does variable export to?

Hi, Unix Gurus, I have a problem need help. I have a script to generate environment variable code same as following: oracle_sid=abcd export oracle_sid when I execute this code with command ./script_nane it succeeded. when I try to find it with env command or echo $oracle_sid, it does not show... (5 Replies)
Discussion started by: ken002
5 Replies

5. Shell Programming and Scripting

Export variable

Hi I have a pass a variable from one script to another. Here are my scripts Script #1 ./profile #!/bin/sh export NAME="Hello" Script #2 ./test #!/bin/sh ./profile echo $NAME when I run ./test .. i am not getting anything .. why is that? (5 Replies)
Discussion started by: arex876
5 Replies

6. Shell Programming and Scripting

Export Variable

How to export variable from one script to other? Can anybody give me syntax for that? Thanks (2 Replies)
Discussion started by: navi
2 Replies

7. Filesystems, Disks and Memory

Export a file system with write permissions

Hi, Is there a way we can export a file system with write permissions for only one user. For eg. we have many users on the network, but only user2 should have write permissions on the exported file system and for others it should be read-only. (7 Replies)
Discussion started by: jredx
7 Replies

8. Filesystems, Disks and Memory

Is it possible to re-export a exported NFS file system?

Hi... Is it possible to re-export a exported NFS file system? If no, Why? Let me know, if any further details are required about the question. Thanks in advance Adams:) (5 Replies)
Discussion started by: Adams Nave
5 Replies

9. UNIX for Dummies Questions & Answers

Export command giving Variable Name vs the Value set for the Variable

I'm having an issue when I export within my program. I'm getting the variable name, not the variable value. I have a configuration file (config.txt) that has the values of the variables set as so: set -a export ARCHIVEPOSourceDir="/interfaces/po/log /interfaces/po/data" export... (2 Replies)
Discussion started by: ParNone
2 Replies

10. Shell Programming and Scripting

Syntax to export any variable

How to export variables on a UNIX prompt. Please provide me syntax. Thanks in advance. Malay (5 Replies)
Discussion started by: malaymaru
5 Replies
Login or Register to Ask a Question