logrotateなしでログファイルのサイズを固定したままにする

logrotateなしでログファイルのサイズを固定したままにする

新しい空のファイルに置き換えて、古いファイルを削除(またはアーカイブ)せずにログファイルのファイルサイズを固定したままにする方法はありますか?たとえば、ログファイルの最大サイズを1 MBに設定すると、ファイルサイズがその制限を超えると自動的に固定され、テキストが「尾」に追加され、テキストの最も古い部分がポップアップします。ファイルサイズを1MBに保ちます。

ベストアンサー1

これを行うには、小さなbashスクリプトを書くことができます。tail -cファイルを上書きするには、特定のバイト数までtailファイルを使用できます。

からman tail

-c, --bytes=N
              output the last N bytes; alternatively, use +N to  output  bytes
              starting with the Nth of each file

   If  the  first  character of N (the number of bytes or lines) is a `+',
   print beginning with the Nth item from the start of each  file,  other‐
   wise, print the last N items in the file.  N may have a multiplier suf‐
   fix:  b  512,  kB  1000,  K  1024,  MB  1000*1000,  M   1024*1024,   GB
   1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

おすすめ記事