Operating System - HP-UX
1834648 Members
2792 Online
110069 Solutions
New Discussion

How come I cannot get what I want from sar immediately?

 
Rashid Ali
Frequent Advisor

How come I cannot get what I want from sar immediately?

I run the command
sar -b 5 20|awk 'BEGIN{printf "Time %rcache %wcache\n"} {print $1, $4, $7}' to get only three columns "time", "%rcache" and "%wcache", but I have to wait for 20*5=100seconds before I get the result, how can I see the results immediately as sar is running?

4 REPLIES 4
Philip Chan_1
Respected Contributor

Re: How come I cannot get what I want from sar immediately?

You waited for 100 sec because awk was expecting ALL the output of "sar -b 5 20" before doing its filtering job.

Try doing your commands in a loop like,

x=0
while [ $x != 20 ]
do
let x=x+1
sar -b 5 1 | awk 'BEGIN{printf "Time %rcache %wcache\n"} {print $1, $4, $7}'
done


~Philip
Philip Chan_1
Respected Contributor

Re: How come I cannot get what I want from sar immediately?

To be more exact,


print "Time %rcache %wcache"
let x=0
while [ $x != 20 ]
do
let x=x+1
sar -b 5 1 | tail -n 1 | awk '{print $1, $4, $7}'
done

You can put this into a script to run.

Cheers,
Philip
Rashid Ali
Frequent Advisor

Re: How come I cannot get what I want from sar immediately?

Thank you for your script. It can work but will that cause additional overhead? Any better alternatives?
Philip Chan_1
Respected Contributor

Re: How come I cannot get what I want from sar immediately?

The overhead is very little which can be disgarded. Better alternatives? Unix systems are so flexible that the same job can be done in different ways. My theory is, don't spend 24 hours for 0.1% improvement.

~Philip