#navi(../)
* topコマンドの出力をファイルに出力する方法 [#baaac57b]
topコマンドの出力をファイルに出力する方法を以下に記します。

#contents
#htmlinsertpcsp(linux_ads_top.html,linux-sp.html)

* 関連記事 [#v1222b48]
-[[htopでターミナルにグラフィカルなプロセス情報を表示する>逆引きUNIXコマンド/htopでターミナルにグラフィカルなプロセス情報を表示する]]

* -bオプションを使用してtopコマンドを実行する [#f0840a8b]
topコマンドの出力をそのままファイルに出力するとエスケープシーケンス情報なども保存されるため再利用する場合は面倒です。~
情報のみを出力するには''-b''オプションを利用します。
以下の例のように使用するとtopの出力をファイルに保存することができます。

-(例)10秒毎に20回情報を取得しtop_result.logに出力結果を保存する
 top -b -d 10 -n 20 > top_result.log

尚、''-b''オプションはバッチモードを示します。

''-S''による累積時間の取得もできるようです。~
man topでバッチモード以外のオプションを調べてみることをお薦めします。

実際に-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コマンドの出力をファイルに保存する方法でした。
 
#htmlinsertpcsp(linux_ads_btm.html,linux-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS