liunx命令行解析top命令响应
top命令返回如下:# top -b -n 2
top - 13:13:02 up4:17,1 user,load average: 0.15, 0.05, 0.01
Tasks: 120 total, 1 running, 119 sleeping, 0 stopped, 0 zombie
Cpu(s):1.1%us,0.2%sy,0.0%ni, 97.6%id,0.9%wa,0.0%hi,0.2%si,0.0%st
Mem: 3925152k total,3587764k used, 337388k free, 160976k buffers
Swap: 10207224k total, 0k used, 10207224k free, 478228k cached
PID USER PRNIVIRTRESSHR S %CPU %MEM TIME+COMMAND
11870 root 20 0 15084 1100832 R1.80.0 0:00.07 top
1 root 20 0 19396 1564 1256 S0.00.0 0:01.07 init
2 root 20 0 0 0 0 S0.00.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S0.00.0 0:00.00 migration/0
4 root 20 0 0 0 0 S0.00.0 0:00.45 ksoftirqd/0
5 root RT 0 0 0 0 S0.00.0 0:00.00 migration/0
6 root RT 0 0 0 0 S0.00.0 0:00.00 watchdog/0
7 root RT 0 0 0 0 S0.00.0 0:00.00 migration/1
8 root RT 0 0 0 0 S0.00.0 0:00.00 migration/1
9 root 20 0 0 0 0 S0.00.0 0:00.16 ksoftirqd/1
10 root RT 0 0 0 0 S0.00.0 0:00.00 watchdog/1
11 root 20 0 0 0 0 S0.00.0 0:00.00 events/0
12 root 20 0 0 0 0 S0.00.0 0:00.03 events/1
13 root 20 0 0 0 0 S0.00.0 0:00.00 cpuset
14 root 20 0 0 0 0 S0.00.0 0:00.00 khelper
15 root 20 0 0 0 0 S0.00.0 0:00.01 netns
16 root 20 0 0 0 0 S0.00.0 0:00.00 async/mgr
17 root 20 0 0 0 0 S0.00.0 0:00.00 pm
18 root 20 0 0 0 0 S0.00.0 0:00.00 sync_supers
19 root 20 0 0 0 0 S0.00.0 0:00.00 bdi-default
20 root 20 0 0 0 0 S0.00.0 0:00.00 kintegrityd/0
21 root 20 0 0 0 0 S0.00.0 0:00.00 kintegrityd/1
现在想使用命令行获取内存和cpu的信息,需要的结果如下:
%CPU %MEM
1.80.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
0.00.0
求高手指点,谢谢! 本帖最后由 royplaygame 于 2013-08-22 13:38 编辑
你可以用如下命令:top -b -n 1 | awk '{print $9,$10}'| sed -n '7,$p'
回复 2# royplaygame
谢谢
回复 2# royplaygame
回复 2# royplaygame
如果是-n 2该如何处理? 不确定行数的。
378110056 发表于 2013-08-22 13:48 static/image/common/back.gif
回复 2# royplaygame
如果是-n 2该如何处理? 不确定行数的。
你的 -n 2是连着做了两次top, 你可以 -n 1做两次,就好了
页:
[1]