这是我上一个问题的后续问题
所以我有这个 shellscript 来监控 Gentoo 上的 nginx 日志文件,问题是日志文件在特定文件大小或一段时间后被重命名和 gzip,shellscript 仍在查找原始文件描述符(或 inode?),新文件内容不会出现。
我的问题是,如何连接到 auto-gzip 脚本以让我的日志文件监控脚本重新启动以监控新的日志文件?
顺便说一句,请不要使用 cronjob 或使用计时器。我想要对我的监控脚本进行近乎实时的响应。
使用-F
标志而不是-f
标志tail
(或者--follow=name
也可以使用,尽管这仅适用于 Linux,但-F
也适用于 BSD 和 Mac OS X):
--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.