linux 监控文件变化
介绍
有时候我们常需要当文件变化的时候便触发某些脚本操作,比如说有文件更新了就同步文件到远程机器。在实现这个操作上,主要用到两个工具,一个是rsync,一个是inotifywait 。inotifywait的作用是监控文件夹变化,rsync是用来同步,可同步到本机的其他目录或者远程服务器上。
安装rsync
wget http://rsync.samba.org/ftp/rsync/src/rsync-3.1.1.tar.gz
tar zxvf rsync-3.1.1.tar.gz
./configure –prefix=/usr/local/rsync-3.1.1
make
make install
安装inotifywait
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make
make install
创建并运行脚本
新建脚本inotifywait.sh 并输入以下内容
#!/bin/bash
export CNROMS_SRC=/home/ftpuser/gri/ # 同步的路径,请根据实际情况修改
inotifywait --exclude '\.(part|swp)' -r -mq -e modify,move_self,create,delete,move,close_write $CNROMS_SRC |
while read event;
do
rsync -vazu --progress --password-file=/etc/rsyncd_rsync.secret /home/ftpuser/gri/sla rsync@10.208.1.1::gri ##这里执行同步的命令,可以改为其他的命令
done
然后执行下面命令,会在后台执行监控
nohup sh inotifywait.sh > /dev/null 2>&1
linux 监控文件变化的更多相关文章
- Python监控文件变化:watchdog
Python监控文件变化有两种库:pyinotify和watchdog.pyinotify依赖于Linux平台的inotify,后者则对不同平台的的事件都进行了封装.也就是说,watchdog跨平台. ...
- JDK 之 NIO 2 WatchService、WatchKey(监控文件变化)
JDK 之 NIO 2 WatchService.WatchKey(监控文件变化) JDK 规范目录(https://www.cnblogs.com/binarylei/p/10200503.html ...
- mac 监控文件变化并重启php
自己撸一个框架,需要监控代码变化 安装fswatch brew install fswatch shell重启PHP脚本reload.sh #!/bin/sh do ps -ef | grep php ...
- inotifywait命令如何监控文件变化?
转载自:https://segmentfault.com/a/1190000038351925 文件监控可以配合rsync实现文件自动同步,例如监听某个目录,当文件变化时,使用rsync命令将变化的文 ...
- Gulp-前端进阶A-3---如何不刷新监控文件变化?
npm install --save-dev gulp-connect npm install --save-dev gulp-livereload npm其他,前面已有 var gulp = req ...
- 使用apache common-io 监控文件变化--转
package common.io; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.common ...
- 利用nodejs监控文件变化并使用sftp上传到服务器
很久没写博客了,因为最近在用react+express做一个自己的工具型网站(其实就是夺宝岛抢拍器) 然后因为经常要改动,而且又要放到服务器上进行测试.总是要webpack,然后手动把文件上传上去,不 ...
- 使用apache common-io 监控文件变化
package common.io; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.common ...
- watchdog监控文件变化使用总结——转载
原文链接地址:https://blog.csdn.net/xufive/article/details/93847372 概述 首先声明,本文讨论的 watchdog,不是单片机里的 watchdog ...
随机推荐
- leetCode题解之求二叉树每层的平均值
1.题目描述 Given a non-empty binary tree, return the average value of the nodes on each level in the for ...
- 7.log4j2的使用
一.简介 log4j2相对于log4j 1.x有了脱胎换骨的变化,其官网宣称的优势有多线程下10几倍于log4j 1.x和logback的高吞吐量.可配置的审计型日志.基于插件架构的各种灵活配置等.如 ...
- statistical thinking in Python EDA
Histgram直方图适合于单个变量的value分布图形 seaborn在matplotlib基础上做了更高层的抽象,方便对基础的图表绘制.也可以继续使用matplotlib直接绘图,但是调用seab ...
- machine learning model(algorithm model) .vs. statistical model
https://www.analyticsvidhya.com/blog/2015/07/difference-machine-learning-statistical-modeling/ http: ...
- HDFS pipeline写 -- datanode
站在DataNode的视角,看看pipeline写的流程,本文不分析客户端部分,从客户端写数据之前拿到了3个可写的block位置说起. 每个datanode会创建一个线程DataXceiverServ ...
- Oracle EBS AR 事务处理到期余额总计API
declare -- Local variables here i integer; x_line_original NUMBER; x_line_remaining NUMBER; ...
- 使用SharpZipLib压缩与解压文件
using ICSharpCode.SharpZipLib.Zip; using System; using System.Collections.Generic; using System.IO; ...
- December 04th 2016 Week 50th Sunday
Learn wisdom by the follies of others. 前车之鉴,后人之师. Maybe my personal state is that others can learn w ...
- codeforces 17D Notepad
codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...
- DotNET中的幕后英雄:MSCOREE.DLL
现在做.NET Framework的开发的朋友应该是越来越多了,但是可能并非人人都对MSCOREE.DLL非常了解.而事实上,毫不夸张地说,MSCOREE.DLL是.NET Framework中最为核 ...