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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find average sar -d

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
I'm trying to find the average %busy,avque. from the sar -d
output

I've got the data and formatted it into the following format

Time Device %busy avque r+w/s blks/s
00:10:00 hdisk0 0 0.0 0 0

What I'm trying to do is (Header not in orginal file)

div=`wc -l disk0.data`
a=0
while read line
do
a=`awk '{print $3}'`
b=`expr $a + $a`
c=`expr $a + $b`
done < disk0.data
d=`expr $c \ $div`
echo &quot;The Average %busy is &quot;$d

I know I'm missing something really obvious


--
| Mike Nixon
| Unix Admin
| ----------------------------
 
Mike - Try this.

div=`wc -l disk0.data | sed -e 's/ *//g' -e 's/disk0.data//'`
a=0
b=0
while read line
do
a=`echo $line |awk '{print $3}'`
b=`expr $b + $a`
done < disk0.data
echo $b
d=`expr $b / $div`
echo &quot;The Average %busy is &quot;$d
 
hi,

we can write an awk script which will be more easier and compact and get the solution you want i think.just try command which i have given..

test.dat has the text contents.
average.awk is the awk script i have written.

try this command.it should work fine i think.

awk -f average.awk test.dat

script average.awk is as follows:

BEGIN { }
{ sum_second_field=sum_second_field+$2;sum_third_field=sum_third_field+$3}
END {print (&quot;The average of second field and third field is &quot;,sum_second_field/NR,&quot; and &quot;,sum_third_field/NR,&quot;respectively&quot;) }

dont you find this more compact and efficient...

Senthil Kumar
 
mike,
i think you would have got confused with my awk script.. instead of $2,$3 change them to $3,$4 respectively in my script as per your requirement.the sum_second_field is %busy and sum_third_field is avque for you okay.

if you have doubts or so, let me know

Senthil Kumar

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top