topコマンドの出力をファイルに出力する方法 †topコマンドの出力をファイルに出力する方法を以下に記します。 関連記事 †-bオプションを使用してtopコマンドを実行する †topコマンドの出力をそのままファイルに出力するとエスケープシーケンス情報なども保存されるため再利用する場合は面倒です。
尚、-bオプションはバッチモードを示します。 -Sによる累積時間の取得もできるようです。 実際に-bオプションを利用して出力された結果は以下のようになります。 $ top -b -d 10 -n 20 > top_result.log $ cat top_result.log top - 11:43:41 up 2:05, 5 users, load average: 0.01, 0.02, 0.00 Tasks: 206 total, 1 running, 203 sleeping, 0 stopped, 2 zombie Cpu(s): 1.4%us, 0.4%sy, 0.0%ni, 96.6%id, 1.5%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 3979276k total, 2540772k used, 1438504k free, 180076k buffers Swap: 2031608k total, 0k used, 2031608k free, 1153832k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 15 0 10364 692 580 S 0.0 0.0 0:01.49 init 2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0 3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1 6 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/1 7 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1 8 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/2 9 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/2 10 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/2 11 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/3 12 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/3 13 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/3 14 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 events/0 15 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 events/1 16 root 10 -5 0 0 0 S 0.0 0.0 0:00.04 events/2 17 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 events/3 18 root 10 -5 0 0 0 S 0.0 0.0 0:00.00 khelper <snip> 以上、topコマンドの出力をファイルに保存する方法でした。 |