[root@linux]# more getcmdout.sh
#!/bin/sh
export PATH=$PATH:/bin
echo "PS out:"
# 第二行开始输出,以%CPU 数字形式倒序排序,取出Top 10;
ps auxw|grep -v grep|sed -n '2,$'p|sort -rn -k 3|head -10
echo "VMSTAT out:";
vmstat
echo "Top out:";
# top命令非交互方式执行1次,第8行开始输出,以%CPU 数字形式倒序排序,取出Top 10;
top -d 1 -b -n 1|sed -n '8,$'p|sort -rn -k 9|head -10
命令输出:
PS out:
root 3838 59.7 78.4 7556732 6411056 ? D 13:14 0:22 /usr/local/bin/redis-server /etc/redis/6379.conf
root 3837 57.7 1.1 109196 90816 pts/2 R+ 13:14 0:23 redis-benchmark -n 50000 -q -r 10000 -d 20480
root 3727 43.9 95.2 8768708 7787392 ? Rsl 13:11 1:24 /usr/local/bin/redis-server /etc/redis/6379.conf
root 359 1.6 0.0 0 0 ? D< 12:53 0:21 [kswapd0]
68 2827 0.1 0.0 31392 1308 ? Ss 12:54 0:01 hald
xfs 3077 0.0 0.0 21068 492 ? Ss 12:54 0:00 xfs -droppriv -daemon
rpc 2639 0.0 0.0 8052 400 ? Ss 12:54 0:00 portmap
root 98 0.0 0.0 0 0 ? S< 12:53 0:00 [kacpid]
root 97 0.0 0.0 0 0 ? S< 12:53 0:00 [kblockd/3]
root 96 0.0 0.0 0 0 ? S< 12:53 0:00 [kblockd/2]
VMSTAT out:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
4 4 1250124 44836 508 11820 23 250 107 273 269 148 1 2 96 1 0
Top out:
3837 root 17 0 106m 88m 620 R97.4 1.1 0:23.95 redis-benchmark
3727 root 16 0 8563m 7.4g 768 R 52.6 94.8 1:24.82 redis-server
359 root 10 -5 0 0 0 D 17.5 0.0 0:21.36 kswapd0
9 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3
98 root 16 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid
97 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kblockd/3
96 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kblockd/2
95 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kblockd/1
94 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 kblockd/0
8 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/3