[原创]持续不断监控文件的变化(如日志)_VMware, Unix及操作系统讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  VMware, Unix及操作系统讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2888 | 回复: 0   主题: [原创]持续不断监控文件的变化(如日志)        下一篇 
wulcan
版主
等级:中校
经验:1795
发帖:124
精华:0
注册:2014-3-19
状态:离线
发送短消息息给wulcan 加好友    发送短消息息给wulcan 发消息
发表于: IP:您无权察看 2014-8-27 9:13:35 | [全部帖] [楼主帖] 楼主

在排查WEB系统故障的时候,需要随时关注日志,最希望只要日志有变动,就显示到屏幕上。
但是普通的日志,只能退出vi再重新进,或者不断的使用tail,有没有简便的方法呢?
其实tail本身就可以做这件事情:

man tail
……
-f The -f option causes tail to not stop when end of file is
reached, but rather to wait for additional data to be appended to
the input. The -f option is ignored if the standard input is a
pipe, but not if it is a FIFO.
-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.
If the file being followed does not (yet) exist or if it is
removed, tail will keep looking and will display the file from
the beginning if and when it is created.
The -F option is the same as the -f option if reading from stan‐
dard input rather than a file.
……


简单说:
 -f 该参数将使tail在遇到文件尾时不退出,而是等待,一旦发现有数据添加到文件,则显示出添加的部分。
-F 同-f,不同的是-F还检查文件是不是被重命名或被滚动。如果tail检测到文件被重建,则重新打开新的文件。
下面示例,开了两个终端,一个启动了tail进行监听aa.txt,另一个对aa.txt进行操作,看两者的表现,为些准备了aa.txt和bb.txt,内容一样:

北京联动北方科技有限公司
在左边终端上开启tail,然后在右边终端上添加两行:

北京联动北方科技有限公司

删除aa.txt,然后再重建aa.txt:

北京联动北方科技有限公司

tail –f就在那儿傻等了,aa.txt已经没有了,它也一直在等待。
用tail –F再试:

北京联动北方科技有限公司

添加行的表现差不多。
再看重新aa.txt的表现:

北京联动北方科技有限公司
能把新文件的内容显示出来了。

该贴由hui.chen转至本版2014-11-5 17:04:55




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论