inotifywait监听php,inotifywait 是一个可以实时监控文件变动的工具

inotifywait 是一个可以实时监控文件变动的工具,它利用linux内核中的inotify机制实现监控功能。

查看内核版本

[root@Oracle ~]# uname -r 2.6.32-220.el6.i686

安装inotify-tools yum install -y inotify-tools 测试监控/etc,inotifywait -m /etc 或监控文件 inotifywait -m /etc/xxx.logs

###

inotifywait 命令参数说明:

-m 选项表示 monitor ,即开启监视

-r 选项表示递归监视,但是会比较慢一些,若监视/etc 目录,其中的子目录下修改文件也是能被监控到。

-e 选项指定要监控的“事件”(events)包括了:access、modify、 attrib、 close_write、 close_nowrite、close、open、 moved_to、 moved_from、move、 move_self、 create、delete、delete_self、unmount。

如果修改了/etc/passwd文件,则把这个事件记录在文件/root/modify_passwd.txt里

inotifywait -m /etc/passwd -e modify > /root/modify_passwd.txt

如果不加参数-e的话,默认就是监控所有的事件,在日常运维时,这个工具可以帮助你监控服务器上重要文件和重要目录的变化情况。

示例:

inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify /data/wwwroot/mall_ecstore/data/debug/aaa | while read file

do

echo -e "======================start===========\n"

tail -n100 /data/wwwroot/mall_ecstore/data/debug/aaa

echo -e "======================end===========\n"

done

tail -f 也可以监控文件内容

tail -f -n 100 /data/wwwroot/mall_ecstore/data/debug/aaa | nl 注: nl显示是行号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值