Linux 将top命令输出的前100行信息保存到文件

最近发现服务器每天晚上10点到第二天早上6-7点,CPU load都异常占用达100%,导致自己的任务一直被阻塞。

为了找到原因,使用top命令并配合grep筛选,将结果保存到文件中,方便分析。

top -b -d 1 | grep ^top -A 200 > top.log

该命令的含义是:

top -b -d 1 每间隔1s刷新一次top结果
| grep ^top -A 200 对每次的top结果进行筛选,只保留前200行
> top.log将筛选后的结果保存到文件中

top
-b 批处理模式
Starts top in Batch mode, which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you’ve set with the `-n’ command-line option or until killed.

-d 更新间隔(秒)

-n top执行次数,若不设置,则一直执行,直到手动kill

参考:
https://blog.csdn.net/michaelwoshi/article/details/121714419
https://ckelsel.blog.csdn.net/article/details/52758063
https://blog.csdn.net/u011852872/article/details/115406680

猜你喜欢

转载自blog.csdn.net/mooneve/article/details/126110981
今日推荐