0

これは私の前の質問のフォローアップの質問です

だから私はGentooでnginxログファイルを監視するためにこのシェルスクリプトを持っています.問題は、ログファイルの名前が変更され、特定のファイルサイズまたは期間の後にgzipされ、シェルスクリプトがまだ元のファイル記述子(またはinode?)を検索していることです.新しいファイルの内容は表示されません。

私の質問は、auto-gzip スクリプトにフックして、ログ ファイル監視スクリプトを再起動して新しいログ ファイルを監視する方法です。

ところで、cronjob やタイマーを使用しないでください。モニター スクリプトのほぼリアルタイムの応答が必要です。

4

1 に答える 1

2

フラグ for-Fの代わりにフラグを使用します(または、Linux でのみ機能しますが、BSD や Mac OS X でも機能します):-ftail--follow=name-F

   --retry
          keep trying to open a file even if it is inaccessible when  tail
          starts  or  if it becomes inaccessible later -- useful only with
          -f

   -f, --follow[={name|descriptor}]
          output appended data as the file grows; -f, --follow, and --fol-
          low=descriptor are equivalent

   -F     same as --follow=name --retry

   With  --follow  (-f),  tail  defaults to following the file descriptor,
   which means that even if a tail’ed file is renamed, tail will  continue
   to  track  its  end.   This  default behavior is not desirable when you
   really want to track the actual name of the file, not the file descrip-
   tor (e.g., log rotation).  Use --follow=name in that case.  That causes
   tail to track the named file by reopening it periodically to see if  it
   has been removed and recreated by some other program.
于 2010-12-10T04:58:32.127 に答える