linux内存平均值,linux - 如何编写Shell脚本以从sar报告中找到最小最大值和平均值以进行ram利用 - 堆栈内存溢出...

跟踪单个awk可能会帮助您。

sar -r -f | awk '

FNR>1&&!/memused/{

max=max>$5?max:$5;

min=min>$5?$5:(min?min:$5);

sum+=$5}

END{

print "Minimum:",min,"Average:",(sum/FNR),"Maximum:",max

}'

编辑:现在也添加了代码说明。

sar -r -f | awk ' ## Sending sar standard output as a standard input by pipe to awk command.

FNR>1&&!/memused/{ ## checking if line number is greater than and not having string memused in it then do following.

max=max>$5?max:$5; ## creating a variable named max and checking if max variable value is greater than 5th field then keep it as max else keep it as 5th field to get the maximum values.

min=min>$5?$5:(min?min:$5); ##creating a variable named min and checking if min value is greater than 5th field if yes then change its value to $5 or check if min is there keep its value to min or if min is NULL then keep it as $5 value.

sum+=$5} ## creating variable named sum and adding its value to itself along with 5th fields value.

END{

print "Minimum:",min,"Average:",(sum/FNR),"Maximum:",max ##Printing string minimum and min value similarly with avg and maximum too.

}'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值