脚本内容:
[root@patrol soft]# cat top10.sh
#!/bin/bash /usr/bin/top -b -n 1 |head -n 17 >> /soft/cputop10.log /bin/ps aux | /bin/grep -v PID | /bin/sort -k+4 -rn | /usr/bin/head > /soft/memtop9.log /bin/sed '1 i/USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND' /soft/memtop9.log >> /soft/memtop10.log rm -rf /soft/memtop9.log
输出的结果:
[root@patrol soft]# cat cputop10.log
top - 11:11:52 up 65 days, 17:28, 3 users, load average: 0.00, 0.00, 0.42
Tasks: 169 total, 1 running, 168 sleeping, 0 stopped, 0 zombie
Cpu(s): 2.6%us, 0.8%sy, 0.7%ni, 95.8%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8062532k total, 6805704k used, 1256828k free, 180316k buffers
Swap: 4136952k total, 41800k used, 4095152k free, 6134716k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 19356 1092 868 S 0.0 0.0 0:01.51 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:13.22 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 17:18.49 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 root RT 0 0 0 0 S 0.0 0.0 0:35.83 watchdog/0
7 root RT 0 0 0 0 S 0.0 0.0 0:33.42 migration/1
8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
9 root 20 0 0 0 0 S 0.0 0.0 20:23.10 ksoftirqd/1
10 root RT 0 0 0 0 S 0.0 0.0 0:24.90 watchdog/1
[root@patrol soft]# cat memtop10.log
/USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2225 0.0 0.1 114860 11964 tty1 Ss+ Jun23 3:27 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-3ekaOM/database -nolisten tcp vt1
root 1735 0.0 0.1 89056 10428 ? Ss Jun23 0:16 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid
gdm 2338 0.1 0.1 352192 8284 ? Ssl Jun23 162:09 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-greeter/settings-manager-plugins
rtkit 2366 0.0 0.0 168452 832 ? SNl Jun23 7:18 /usr/libexec/rtkit-daemon
rpcuser 1595 0.0 0.0 23344 708 ? Ss Jun23 0:00 rpc.statd
rpc 1577 0.0 0.0 19032 832 ? Ss Jun23 0:20 rpcbind
root 992 0.0 0.0 0 0 ? S Jun23 0:00 [ext4-dio-unwrit]
root 991 0.0 0.0 0 0 ? S Jun23 0:00 [ext4-dio-unwrit]
root 990 0.0 0.0 0 0 ? S Jun23 0:00 [ext4-dio-unwrit]
root 989 0.0 0.0 0 0 ? S Jun23 0:00 [ext4-dio-unwrit]
转载于:https://blog.51cto.com/qiushi/1689270