尾矿滚动文件 [英] Tailing Rolling Files

查看:111
本文介绍了尾矿滚动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录完全滚动日志文件,我希望能够在使用的尾巴。

I have a directory full of rolling log files that I would like to be able to use tail on.

该文件被命名为这样的:

The files are named as such:

name      modified
00A.txt   Dec 27 19:00
00B.txt   Dec 27 19:01
00C.txt   Dec 27 19:02
00D.txt   Dec 27 19:03

在较早的UNIX系统上,我试图想出了将尾部的特定目录中最近修改的文件,如果该文件被关闭行政(滚动到下一个文件)我想一个shell脚本程序自动开始拖尾新的文件有没有我打出来的尾巴重新运行。

On an older unix system, I'm trying to come up with a shell script that will tail the most recently modified file in a specific directory, and if that file gets administratively closed (rolls to the next file) I want the program to automatically begin tailing the new file without me having to break out of tail to rerun.

tail -100f `ls -t | head -1` 

期望的行为,因为上面的文件名,会是这样的:

The desired behavior, given the filenames above, would go like this:

./logtailer.sh

然后脚本将开始拖尾00D.txt。只要记录器是完成写入00D.txt,现在最新的日志文件被命名为00E.txt,程序会自动开始拖尾该文件。

Then the script would begin tailing 00D.txt. As soon as the logger was finished writing to 00D.txt and the newest log file was now named 00E.txt, the program would automatically begin tailing that file.

人们可以通过观察尾的输出文本文件在行政关闭,然后再次具有以下命令运行写这个剧本。

One could write this script by watching the output of tail for the text "File Administratively Closed" and then having the following command run again.

tail -100f `ls -t | head -1`

有没有更优雅的方式来做到这一点比看文本文件,行政关闭?我怎么能甚至逐行读取输出尾行的shell脚本?

Is there a more elegant way to do this than by watching for the text "file administratively closed"? How can I even read the output of tail line by line in a shell script?

编辑:我要解释的是,尾-F标志是在此系统上我的选择。它使用了不同版本尾巴不包含此功能。
操作系统版本 - 的Solaris 10

I should explain that the -F flag for tail is not an option for me on this system. It uses a different version of tail that does not contain this feature. OS version - Solaris 10

推荐答案

您可以使用 -F 选项这意味着 - 遵循=名称--retry

页:

-F      
The -F option implies the -f option, but tail will also check to see if the 
file being followed has been renamed or rotated.  The file is closed and 
reopened when tail detects that the filename being read from has a new inode 
number. The -F option is ignored if reading from standard input rather than 
a file.

这篇关于尾矿滚动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆