inotifywait实现目录监控
2015-05-25 14:10
218 查看
inotifywait实现目录监控
分类: Linux编程 操作系统2012-11-1522:09 3230人阅读 评论(0) 收藏 举报
传统的rsync+crontab同步数据和实际会有差异,而inotify则基本可以达到实时的效果,当文件有任何变动,就会触发inotify。
inotify 是一个 Linux 内核特性,它监控文件系统,并且及时向专门的应用程序发出相关的事件警告,比如删除、读、写和卸载操作等。inotify安装完成之后会有两个命令,
inotifywait 和 inotifywatch。inotifywait用于等待文件或者文件集上的一个特定事件,可以监控任何文件或者目录位置,并且可以递归地监控整个目录树;inotifywatch 用于收集被监控的文件系统统计数据,包括每个inotify事件发生多少次等信息。
安装
cd /tmp
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz --no-check-certificate
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure&&make&&make install
ln -sv /usr/local/lib/libinotify* /usr/lib/
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
# vim /tmp/mon.sh
#!/bin/bash
src=/tmp/test/ # directory to monitor
/usr/local/bin/inotifywait -rmq -e modify $src | while read event
do
echo "hello" >> 1.txt
done
做成开机启动
chmod u+x /tmp/mon.sh
echo "nohup /bin/bash /tmp/mon.sh &" >> /etc/rc.d/rc.local
nohup /bin/bash /tmp/mon.sh &
这时候只要/tmp/test/一有改动,在会触发inotifywait,运行echo命令。
相关文章推荐
- inotifywait实现目录监控
- inotifywait实现目录监控
- Linux下,借助inotifywait工具,对文件目录进行监控
- 利用inotifywait监控主机文件和目录
- 利用inotifywait监控主机文件和目录
- 利用inotifywait监控主机文件和目录
- 使用inotify实现linux系统下的目录变化监控
- inotifywait监控目录更改
- swoole+inotify实现异步实时文件监控
- C#实现对文件目录的实时监控
- C#实现对文件目录的实时监控
- 基于redis ae实现 Linux中的文件系统监控机制(inotify)
- Java实现监控目录下文件变化
- rsync+inotify 实现资源服务器的同步目录下的文件变化时,备份服务器的同步目录更新,以资源服务器为准,去同步其他客户端
- 市面上所有号称"虚拟机","防火墙"的实时监控杀毒软件无一不是使用的IFSHOOK技术.但是同时也有一些朋友不断写MAIL给我打听如何实现读写的监控.下面给出用VTOOLSD写的代码.也就是所有实时杀毒软件的奥秘.同时,很多拦截文件操作的软件,例如对目录加
- inotify-tool基于linux文件和目录的监控
- C#实现实时监控文件目录下的变化
- inotifywait命令_Linux inotifywait 命令用法详解:异步文件系统监控机制
- rsync+inotify 实现资源服务器的同步目录下的文件变化时,备份服务器的同步目录更新,以资源服务器为准,去同步其他客户端