inotifywait实现目录监控--http://man.linuxde.net/inotifywait
sudo apt install inotify-tools
while inotifywait -q -r -e create,delete,modify,move,attrib
--exclude "/\." /etc/nginx/ /data/conf/nginx/; do nginx -t
&& nginx -s reload; done
传统的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实现目录监控--http://man.linuxde.net/inotifywait的更多相关文章
- inotifywait实现目录监控
http://blog.csdn.net/firefoxbug/article/details/8188804
- Delphi目录监控、目录监听
资料地址: 1.https://www.cnblogs.com/studypanp/p/4890970.html 单元代码: (************************************ ...
- inotifywait实现文件监控
应用场景文件监控可以配合rsync实现文件自动同步,例如监听某个目录,当文件变化时,使用rsync命令将变化的文件同步.(可用于代码自动发布) 安装noitify下载地址:http://github. ...
- inotifywait命令如何监控文件变化?
转载自:https://segmentfault.com/a/1190000038351925 文件监控可以配合rsync实现文件自动同步,例如监听某个目录,当文件变化时,使用rsync命令将变化的文 ...
- diamond源码阅读-目录监控
PathNode(Path)StandardWatchEventKind(WatchEvent)Watchable(WatchKey WatchService WatchEvent)WatchKey( ...
- Shell-WEB目录监控
#!/bin/sh #date:2015-12-08 #filename:check_webfile.sh #作者:李兴利 #Email:1162572407@qq.com #version:v1.1 ...
- 编译安装inotify-tools和监控inotifywait事件
编译安装inotify-tools软件包 1)解包inotify-tools-3.13.tar.gz文件 [root@svr7~]#ls inotify-tools- ...
- 使用inotify实现linux系统下的目录变化监控
近期,有个项目须要及时删除Nginx服务生成的缓存文件,因为不是非常了解Nginx缓存生成的策略,在网上也沒有细致找,经过大家讨论,终于希望引入liunx的inotify功能,监控某个liunx文件夹 ...
- php使用inotify扩展监控文件或目录的变化
一.安装inotify扩展 1.下载inotify扩展源码 https://pecl.php.net/package/inotify 对于php7以上版本,请下载 inotify-2.0.0.tgz. ...
随机推荐
- React Native for Android应用名及图标修改
应用开发完了,总不能顶着MyProject和小机器人图标就发布了吧?在发布之前,有多处需要修改的地方.今天我们来全面的看一下 应用ID 俗称PackageName,或APP ID.注意,在gradle ...
- Android解决NDK not configured问题
问题描述: // Error:Execution failed for task ':SoftkeyApp:compileDebugNdk'. // > NDK not configured. ...
- Shell脚本编程(二):shell变量
定义变量 定义变量时,变量名不加美元符号($,PHP语言中变量需要),如: your_name="runoob.com" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编程 ...
- lua -- 所有UI组件的基类
-- 组件行为基础 local Behavior = class("Behavior"); function Behavior:ctor(name) self.owner = ni ...
- Gradle依赖的统一管理,解决依赖冲突
看见别人在用implementation rootProject.ext.dependencies["xxxx"]不知道是什么意思,上网查了一下,原来是为了解决或者说预防gradl ...
- 如何解决安装VMware后郑广电宽带客户端不能登录的问题?
如何解决安装VMware后郑广电宽带客户端不能登录的问题? 问题:安装VMware后,郑广电宽带客户端不能登录,提示:“不允许代理上网”. 解决:将VMware的虚拟网卡(VMnet1和VMnet8) ...
- python中的生成器函数是如何工作的?
以下内容基于python3.4 1. python中的普通函数是怎么运行的? 当一个python函数在执行时,它会在相应的python栈帧上运行,栈帧表示程序运行时函数调用栈中的某一帧.想要获得某个函 ...
- linux mysql卸载
卸载mysql 1.查找以前是否装有mysql 命令:rpm -qa|grep -i mysql 可以看到mysql的包: mysql-libs-5.1.71-1.el6.x86_64 2.删除mys ...
- [Artoolkit] kpmMatching & Tracking of nftSimple
1. kpmMatching thread main() --> loadNFTData() --> trackingInitInit() --> In static void *t ...
- 【Dubbo 源码解析】01_Dubbo 设计简介
Dubbo 设计简介 Dubbo 采用 Microkernel + Plugin (微内核 + 插件)模式,Microkernel 只负责组装 Plugin,Dubbo 自身的功能也是通过扩展点实现的 ...