![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
grep -v '= *$' <textfile>
|
|
#3
|
|||
|
|||
|
Assuming your ksh is ksh93
Code:
curt=$(/sbin/sysconfig -q envmon env_current_temp)
curt=${curt: -2}
|
|
#4
|
|||
|
|||
|
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" |
|||
| Google The UNIX and Linux Forums |