In its broadest sense, learning can be defined as a process of progressive change from ignorance to knowledge, and from indifference to understanding....

using top&gawk to get mem/cpu/swap info on linux

上一篇 / 下一篇  2008-03-15 11:32:48 / 个人分类:Shell & Perl

cpu=`top -n 1 -b | grep ‘Cpu’ |gawk ‘{print 100-substr($8,1,length($8)-1)}’`

mem=`top -n 1 -b | grep ‘Mem’ |gawk ‘{print substr((substr($2,1,length($2)-1)-substr($6,1,length($6)-1))/substr($2,1,length($2)-1)*100,1,index((substr($2,1,length($2)-1)-substr($6,1,length($6)-1))/substr($2,1,length($2)-1)*100,”.”)+1)}’`

swap=`top -n 1 -b | grep ‘Swap’ |gawk ‘{print substr((substr($2,1,length($2)-1)-substr($6,1,length($6)-1))/substr($2,1,length($2)-1)*100,1,index((substr($2,1,length($2)-1)-substr($6,1,length($6)-1))/substr($2,1,length($2)-1)*100,”.”)+1)}’`

echo “$(date ‘+%D’) $(top -n 1 -b | grep ‘top -‘ |awk ‘{print $3}’),$cpu,$mem,$swap” >>test.log

test.log

03/08/07 12:21:33,4.7,69.3,1.6


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-03  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 6793
  • 日志数: 928
  • 影音数: 2
  • 文件数: 2
  • 书签数: 3
  • 建立时间: 2008-02-17
  • 更新时间: 2008-12-02

RSS订阅

Open Toolbar