inotify

php inotify blocking but with timeout

吃可爱长大的小学妹 提交于 2019-12-11 03:06:24
问题 I want to use the pecl extension to php and use the inotify_read() function to detect changes in a file. As a fail safe, I would like to specify a timeout value to the inotify_read function, just so I don't wind up blocking forever, in case an event is raised and is missed. Does anyone know how to use the stream_select function to block for a specified number of seconds, but return immediately if an event is raised on the inotify_read. I know there is way to perform the inotify_read non

Inotify linux watching subdirectories

旧街凉风 提交于 2019-12-11 02:07:53
问题 is it possible to watch directories in this pattern /storage/data/usernames/Download/ -> /storage/data/*/Download/ I need to watch if changes are made in Download folder of each user. Maybe i need to create list of all paths, put it in array and with loop start inotify processes on each folder, but this may be to heavy for system. 回答1: Yes, it is easily possible. folders are created dynamically that's why i want to skip username part and watch all folders with name Download. fluffy is the

inotify stops monitoring file when the file is deleted and created again

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:18:02
问题 I encounter some problem when using inotify. I use inotify to monitor changes on files. Here is my code: int fd = inotify_init(); int wd = inotify_add_watch(fd, "/root/temp", IN_ALL_EVENTS); int bufSize = 1000; char *buf = new char[bufSize]; memset(buf, 0, sizeof(buf)); int nBytes = read(fd, buf, bufSize - 1); cout << nBytes << " bytes read" << endl; inotify_event *eventPtr = (inotify_event *)buf; int offset = 0; while (offset < nBytes) { cout << eventPtr->mask << endl; offset += sizeof

inotifywait in docker-container doesn't register changes

房东的猫 提交于 2019-12-10 12:49:18
问题 I have a script running inside a docker-container which listens for changes in a directory via inotifywait . The directory is mounted to the host-system via docker -v . For some reason, inotifywait doesn't get triggered when files inside this directory is changed. This is the problematic script-line inotifywait -e create -e modify -e delete -e move /etc/nginx/sites-enabled The container is started like this (via fig) web: build: . ports: - "80:80" volumes: - ./conf:/etc/nginx/sites-enabled

多台服务器文件实时同步 rsync+inotify

风流意气都作罢 提交于 2019-12-10 12:31:42
多台服务器文件实时同步 rsync+inotify 前言 当线上服务器有多台并且又没有运维的时候,传输文件就成了一件非常麻烦的事儿,每次传代码都需要登录多台服务器,很容易就漏传了文件,这时候就需要一个自动化的文件同步工具了。 虚拟机服务端:192.168.146.103 虚拟机客户端1:192.168.146.102 虚拟机客户端2:192.168.146.104 系统:centos6.5 关于rsync 与传统的cp、tar备份方式相比,rsync具有安全性高、备份迅速、支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据到远端服务器,对本地磁盘定期做数据镜像等。 关于inotify inotify是一种强大的、细粒度的、异步的文件系统事件监控机制,linux内核从2.6.13起,加入了inotify支持,通过inotify可以监控文件系统中添加、删除,修改、移动等各种细微事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而inotify-tools就是这样的一个第三方软件。 1、服务端安装rsync 检查服务器是否已经安装rsync rpm -aq rsync 如果存在可以卸载之后再重新安装最新版,如果不存在直接安装。以下两种方式选择一种安装。 选择1、自动安装: yum install -y rsync

In a small script to monitor a folder for new files, the script seems to be finding the wrong files

三世轮回 提交于 2019-12-10 11:49:03
问题 I'm using this script to monitor the downloads folder for new .bin files being created. However, it doesn't seem to be working. If I remove the grep, I can make it copy any file created in the Downloads folder, but with the grep it's not working. I suspect the problem is how I'm trying to compare the two values, but I'm really not sure what to do. #!/bin/sh downloadDir="$HOME/Downloads/" mbedDir="/media/mbed" inotifywait -m --format %f -e create $downloadDir -q | \ while read line; do if [ $

inotify recursively how to do it?

馋奶兔 提交于 2019-12-10 05:07:40
问题 i need to print events on a folder with multiple subfolders. how to do it recursivly? Please print a c++ code. I am stucked!! Every time the evet is poped i need to open the subfolder, take the file and copy it into another directory. I don't want to list all the subfolders in every 2 seconds and find the files if there are any. Is not efficient. I need to use a monitor folder. Please help The director that i want to monitor has multiple subfolders. Each subfolder has another subfolder that

linux系统中rsync+inotify实现服务器之间文件实时同步

女生的网名这么多〃 提交于 2019-12-09 18:56:00
之前做了“ssh信任与scp自动传输脚本”的技术文档,此方案是作为公司里备份的方法,但在实际的运行中,由于主服务器在给备份服务器传输的时候,我们的主服务器需要备份的文件是实时、不停的产生的,造成不知道主服务器给备份服务器传输了多少文件,磁盘空间就那么大,做备份的原因:一个是为了保持文件,另外一个是解决主服务器的磁盘饱满问题,但由于不知道备份服务器到底接收了多少文件,所以主服务器里的文件不敢删除(如果没有备份的情况下删除,问题就严重了,我这个是政府的项目,服务器里的文件都是重要的,删错了就走人~~~~(>_<)~~~~ ),所以我就采用了rsync+inotify的方式来实时同时服务器之间的文件,而且传输的过程是加密的,比scp安全多了(即使scp采用ssh信任,用密钥,也不是万无一失的)。 以下是我给公司运维做的备份技术文档,分享给大家,希望对大家有帮助。 先介绍一下rsync与inotify,都在在网上找的资料。先声明下面的rsync与inotify介绍不是我自己写的。 1、rsync 与传统的cp、tar备份方式相比,rsync具有安全性高、备份迅速、支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据到远端服务器,对本地磁盘定期做数据镜像等。 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求

CentOS7下Rsync+sersync实现数据实时同步

↘锁芯ラ 提交于 2019-12-09 18:33:34
CentOS7下Rsync+sersync实现数据实时同步 [日期:2017-10-22] 来源:Linux社区 作者:Linux [字体: 大 中 小 ] 前言: 一、为什么要用Rsync+sersync架构? 1、sersync是基于Inotify开发的,类似于Inotify-tools的工具 2、sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字,然后使用rsync同步的时候,只同步发生变化的这个文件或者这个目录。 二、Rsync+Inotify-tools与Rsync+sersync这两种架构有什么区别? 1、Rsync+Inotify-tools (1):Inotify-tools只能记录下被监听的目录发生了变化(包括增加、删除、修改),并没有把具体是哪个文件或者哪个目录发生了变化记录下来; (2):rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),因此,效率很低。 2、Rsync+sersync (1):sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字; (2):rsync在同步的时候,只同步发生变化的这个文件或者这个目录

how to make sure not to read a file before finishing the write to it

扶醉桌前 提交于 2019-12-09 18:31:40
问题 When trying to monitor a directory using inotify on Linux, as we know, we get notified as soon as the file gets created (before the other process finish writing to it) Is there an effective way to make sure that the file is not read before writing to it is complete by the other process? We could potentially add a delayed read; but as we all know, it is flawed. For a little bit more clarity on the scenario; the two processes are running as different users; the load expected is about a few