所以我有这个shellcript来监视Gentoo上的nginx日志文件,问题是日志文件在某个文件大小或一段时间后被重命名和gziped,shellcript仍然查找原始文件描述符(或inode? ),新文件内容不会显示。
我的问题是,如何挂钩auto-gzip脚本以重新启动我的日志文件监视器脚本以监视新日志文件?
BTW请不要使用cronjob或使用计时器。我想要一个近乎实时的监控脚本响应。
答案 0 :(得分:2)
使用-F
标志代替tail
的-f
标记(或--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.