tkuchikiの日記

新ブログ https://blog.tkuchiki.net

sar で Invalid system activity file が出るファイルを一括削除するスクリプト

sar を使っている時に、

Invalid system activity file

または、

システム動作情報ファイルの形式が正しくありません

というエラーメッセージが表示されて使えないことがあります。
SYSSTAT の 2.1 を見ると、

You are trying to use a file which is not a system activity file, or whose format is no longer compatible with that of files created by current version of sar.
If you were trying to use the standard system activity files located in the /var/log/sa directory then the solution is easy: Just log in as root and remove by hand all the files located in the /var/log/sa directory:

# rm /var/log/sa/sa??

と書いてあるので、消してしまうのが楽なようです。

一つ一つ調べるのは面倒なので、
以下のスクリプトを実行すると、エラーがでたファイルだけ削除できます。