ファイルを記録するには、毎日sarを実行してください。

ファイルを記録するには、毎日sarを実行してください。

sarcronを使用して毎日このコマンドを実行してから終了し、24時間ごとに新しいログファイルの作成を再開するにはどうすればよいですか?

注文する:

sar -u 300 288 >> $(date "+ %Y-%m-%d")-cpu.log

これにより、24時間で15分ごとに使用量が記録されます。

これは適切なbashスクリプトですか?

#!/bin/bash

# Kill current process
kill sar

# Start new sar
sar -u 300 290 >> $(date "+ %Y-%m-%d")-cpu.log

ベストアンサー1

ほとんどのLinuxディストリビューション(すべてではありませんが)では、このデータはsarすでに/var/log...-oman sar

    -o [ filename ]
          Save the readings in the file in binary form. Each reading is in a  separate  record.  The  default
          value of the filename parameter is the current daily data file, the /var/log/sysstat/sadd file. The
          -o option is exclusive of the -f option.  All the data available from the kernel are saved  in  the
          file  (in  fact,  sar  calls  its  data collector sadc with the option "-S ALL". See sadc(8) manual
          page).

を使用してこのバイナリファイルを読み取ることができますsar -f filename

データ収集プロセスを処理する必要がある場合を確認してくださいman sadc

おすすめ記事