Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I awk the current load average without a , ? 0.31 not 0.31, 1

Status
Not open for further replies.

john99999

Instructor
Apr 29, 2005
73
0
0
US
root@server1 [/]# uptime
9:02am up 29 days, 14:39, 2 users, load average: 0.31, 0.24, 0.59
root@server1 [/]# uptime | awk {'print $10'}
0.31,

I want it to display 0.31 not 0.31,

What would the correct command be?
 
uptime | nawk -F'[, ]*' '{print $11}'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Why wont this if statement work?

root@server1 [/]# cat ss
#!/bin/sh

a=`uptime | awk -F'[, ]*' '{print $11}'`;
echo "a = $a"
if [ $a -gt 0.2 ]
then
echo "high load"
fi
root@server1 [/]# ./ss
a = 0.19
./ss: [: 0.19: integer expression expected
 
it says "integer expression expected"

Why can't I compare a float number?
 
It wont even work in C shell
root@server1 [/]# ./ss3
if: Badly formed number.
root@server1 [/]# cat ss3
#! /bin/csh -f
set X=3.1
set Y=4.1
if ( $X < $Y ) then
echo "\$X=${X}, which is greater than \$Y=${Y}"
endif
 
the shells you've mentioned support OONLY interger arithmetic.
here's one of the ways around it:

Code:
#!/bin/ksh

a=1.72
b=1.71

if [ "$(echo "if (${a} > ${b}) 1" | bc)" -eq 1 ] ; then
   echo ">"
else
   echo "<"
fi;

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
What is a shell that supports float arithmetic?
 
ksh93 or if on Solaris /usr/dt/bin/dtksh

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
I tried it in perl but it doesnt store the right value to $a as it does in bash or cshell:
root@server1 [/]# cat ss4
#!/usr/bin/perl
$a=`uptime | awk -F'[, ]*' '{print $11}'`;
#echo "a = $a"
if ( $a > 5.2 ){
print $a;
}


root@server1 [/]# ./ss4
12:34pm up 29 days, 18:11, 1 user, load average: 0.43, 0.32, 0.33
 
why are you spawnning 'uptime' pipped to awk from within perl?
wouldn't it be easier to parse the output of uptime natively within perl?

what is the value of '$a' prior to comparison?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
How can I parse the output of uptime natively within perl?
 
sorry, I'm no perl expert - it looked strange seeing awk being used within perl.
someone on this forum will try to answer OR you can post your question at [forum219]

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi John

I have answered this on the Perl forum


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top