加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 拖尾文件

发布时间:2020-12-15 18:52:41 所属栏目:安全 来源:网络整理
导读:我有一个完整的滚动日志文件的目录,我希望能够使用tail. 这些文件被命名为: name modified00A.txt Dec 27 19:0000B.txt Dec 27 19:0100C.txt Dec 27 19:0200D.txt Dec 27 19:03 在一个较旧的unix系统上,我试图提出一个shell脚本,它会拖尾到特定目录中最近修
我有一个完整的滚动日志文件的目录,我希望能够使用tail.

这些文件被命名为:

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脚本,它会拖尾到特定目录中最近修改的文件,如果该文件被管理上关闭(滚到下一个文件),我希望程序自动开始拖尾新的文件,而不用我的尾巴重新运行.

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

给定上述文件名的所需行为将如下所示:

./logtailer.sh

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

可以通过观察文本“文件管理关闭”的尾部的输出来编写此脚本,然后再次运行以下命令.

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

是否有更优雅的方式来做这个比通过看文本“文件管理关闭”?我甚至可以在shell脚本中逐行读取尾部的输出?

编辑:我应该解释一下,在这个系统上,-F标志的尾部不是我的选择.它使用不包含此功能的不同版本的尾部.
操作系统版本 – Solaris 10

您可以使用-F选项来显示尾部,这意味着–follow = name –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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读