介绍

有时候我们常需要当文件变化的时候便触发某些脚本操作,比如说有文件更新了就同步文件到远程机器。在实现这个操作上,主要用到两个工具,一个是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 监控文件变化的更多相关文章

  1. Python监控文件变化:watchdog

    Python监控文件变化有两种库:pyinotify和watchdog.pyinotify依赖于Linux平台的inotify,后者则对不同平台的的事件都进行了封装.也就是说,watchdog跨平台. ...

  2. JDK 之 NIO 2 WatchService、WatchKey(监控文件变化)

    JDK 之 NIO 2 WatchService.WatchKey(监控文件变化) JDK 规范目录(https://www.cnblogs.com/binarylei/p/10200503.html ...

  3. mac 监控文件变化并重启php

    自己撸一个框架,需要监控代码变化 安装fswatch brew install fswatch shell重启PHP脚本reload.sh #!/bin/sh do ps -ef | grep php ...

  4. inotifywait命令如何监控文件变化?

    转载自:https://segmentfault.com/a/1190000038351925 文件监控可以配合rsync实现文件自动同步,例如监听某个目录,当文件变化时,使用rsync命令将变化的文 ...

  5. Gulp-前端进阶A-3---如何不刷新监控文件变化?

    npm install --save-dev gulp-connect npm install --save-dev gulp-livereload npm其他,前面已有 var gulp = req ...

  6. 使用apache common-io 监控文件变化--转

    package common.io; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.common ...

  7. 利用nodejs监控文件变化并使用sftp上传到服务器

    很久没写博客了,因为最近在用react+express做一个自己的工具型网站(其实就是夺宝岛抢拍器) 然后因为经常要改动,而且又要放到服务器上进行测试.总是要webpack,然后手动把文件上传上去,不 ...

  8. 使用apache common-io 监控文件变化

    package common.io; import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.common ...

  9. watchdog监控文件变化使用总结——转载

    原文链接地址:https://blog.csdn.net/xufive/article/details/93847372 概述 首先声明,本文讨论的 watchdog,不是单片机里的 watchdog ...

随机推荐

  1. 切片和append操作

    本文转自:http://meia.fun/article/1541470004286 学习切片时,被append这个方法困扰了半天:在main方法中把一个切片作为实参传递给另一个函数,并在这个函数内调 ...

  2. leetCode题解之求二叉树每层的平均值

    1.题目描述 Given a non-empty binary tree, return the average value of the nodes on each level in the for ...

  3. [翻译] UCZProgressView

    UCZProgressView UCZProgressView is a circular progress indicator with cool animations for image load ...

  4. [翻译] About Core Image

    About Core Image Core Image is an image processing and analysis technology designed to provide near ...

  5. 使用UICollectionView

    使用UICollectionView 使用UICollectionView的流程: 1. 设定一个UICollectionViewFlowLayout 2. 使用这个设定的UICollectionVi ...

  6. route命令使用

    ---恢复内容开始--- 利用route命令可以实现内外网同时访问 route 命令参数: route [-f] [-p] [Command [Destination] [mask Netmask] ...

  7. Spring Boot Mybatis-Plus

    Mybatis-Plus 是对 Mybatis-Plus 的一些扩充. 在 Spring Boot 中进行集成的时候其实基本上和 mybatis 是一致的. 在你的配置文件中.配置 你的 entity ...

  8. ubuntu安装pycharm并设置快捷方式

    一.tar.gz包安装 从官网下载压缩包 tar zxfv pycharm-professional-2017.3.3.tar.gz cd pycharm-2017.3.3 ./bin/pycharm ...

  9. 本地项目关联git仓库

    Command line instructions Git global setup git config --global user.name "zhoushuo" git co ...

  10. 搭建高可用mysql系列(2)-- Percona XtraDB Cluster 安装

    本文主要介绍在 centos 下 Percona XtraDB Cluster(下文简称PXC) 的安装, 个人的系统版本信息如下: [root@c2-d09 worker]# more /etc/r ...