inotify

inotify - how to find out which user has modified file?

折月煮酒 提交于 2019-12-03 07:02:56
I'm looking for guidance on how to find out which user has modified a particular file. While inotify is great to get notification when a particular file is touched, how do I figure out which user has modified that file? I can think of using lsof but I'm afraid that it may not be as "realtime" as I want and/or it might be too much of a tax on resources. By realtime, I mean that if a user simply executes a touch command on a file, by the time I run lsof on file, it may not be picked up by lsof . You can use audit deamon : sudo apt-get install auditd Choose a file to monitor touch /tmp/myfile Add

Monitoring file using inotify

喜欢而已 提交于 2019-12-03 03:31:53
I am using inotify to monitor a local file, for example "/root/temp" using inotify_add_watch(fd, "/root/temp", mask). When this file is deleted, the program will be blocked by read(fd, buf, bufSize) function. Even if I create a new "/root/temp" file, the program is still block by read function. I am wondering if inotify can detect that the monitored file is created and the read function can get something from fd so that read will not be blocked forever. Here is my code: uint32_t mask = IN_ALL_EVENTS; int fd = inotify_init(); int wd = inotify_add_watch(fd, "/root/temp", mask); char *buf = new

How could I detect when a directory is mounted with inotify?

隐身守侯 提交于 2019-12-03 02:58:47
I'm using Linux Inotify to detect FS events on my program. How could I be notified when a device is mounted on a monitored directory? I don't think you can do it with inotify . Here is the method though: Read uevents from kernel via a Netlink socket and filter out those where "ACTION" is not "mount" . Read and parse "/proc/mounts" when you get an event with a "mount" action. Find a record for a mount point with device that was just mounted and filter it out if it's not the directory you are watching. EDIT: Update to be less than 5 years obsolete If you're on anything but the most ancient of

unison+inotify实现文件双向同步

筅森魡賤 提交于 2019-12-03 02:28:07
Linux文件双向同步 1、方案选择   在网上搜寻了很多方案,在liux下做文件同步,有如下几种方式:   1、nfs实现web数据共享;   2、rsync +inotify实现web数据同步;   3、rsync+sersync更快更节约资源实现web数据同步;   4、unison+inotify实现web数据双向同步;   在这里详细介绍第四种方案,前几种都有些各自的不足。只有第四种方案支持双向实时同步,且当其中一台服务器宕机,也不会影响web的访问。(ps:其实nfs配置非常简单实用,但是其有个致命的缺点就是其中一台web服务挂掉之后,会直接导致web页面无法访问)。 2、环境需求分析   现在有两台图片服务器用keepalive做主备,暂叫做img1(主)、img2(备),img1的图片存储目录平时会频繁读写而且通过nginx提供图片访问服务,但如果img1在特殊情况下无法连接或访问了,需要img2服务器提供前端读写和后端访问的能力,且在img1恢复后能将这期间存储在img2上的图片同步到img1。   Unison+inotify可以完美满足这个需求。   Unison是windows和unix平台下都可以使用的双向文件同步工具,它能使两个文件夹(本地或网络上的)保持内容的一致。 unison 拥有其它一些同步工具或文件系统 的相同特性,但也有自己的特点:   1

How do I find out what inotify watches have been registered?

落花浮王杯 提交于 2019-12-03 02:12:56
问题 I have my inotify watch limit set to 1024 (I think the default is 128?). Despite that, yeoman, Guard and Dropbox constantly fail, and tell me to up my inotify limit. Before doing so, I'd like to know what's consuming all my watches (I have very few files in my Dropbox). Is there some area of /proc or /sys, or some tool I can run, to find out what watches are currently registered? 回答1: inotify filesystem options sysctl fs.inotify opened files lsof | grep inotify | wc -l Increase the values

npm ERR! Failed at the project@0.0.1 start script 'react-native start'

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: npm -v : 3.10.10 react-native -v :0.1.7 node -v : v6.9.5 ubuntu: 16.04 watchman -v : 4.5.0 Afrer executing react-native init project cd project and react-native run-android ,When i execute npm start to run server i have this error : project@0.0.1 start /home/sofiane/projet/merde2 > react-native start Cannot parse yarn version: 0.22 Scanning 547 folders for symlinks in /home/sofiane/projet/project/node_modules (3ms) ┌――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――┐ │ Running packager on port 8081. │ │ │ │ Keep

Unsupported platform for inotify@1.4.1: wanted {“os”:“linux”,“arch”:“any”}

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am coming across a very bizarre error when installing packages for my webpack/reactjs application. I am currently trying to install npm install copy-webpack-plugin --save dev The build/start scripts fail and the following error is shown in the terminal: Unsupported platform for inotify@1.4.1: wanted {"os":"linux","arch":"any"} (current: {"os":"darwin","arch":"x64"}) This means absolutely noting to me and I cannot find any clear explanations online.I do not know why inotify is needed or when/where it has been installed. Package.json scripts

rsync+inotify搭建实时同步系统

匿名 (未验证) 提交于 2019-12-03 00:39:02
Rsync 优点 rsync具有安全性高、备份迅速、支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期地备份文件服务器数据到远程服务器上,对本地磁盘定期进行数据镜像等。 Rsync 不足 随着应用系统规模的不断扩大,对数据的安全性和可靠性提出了更高的要求,rsync便暴露出了很多不足之处。首先,rsync同步数据时,需要扫描所有文件后进行比对,然后进行差量传输。如果文件数量达到了百万量级及以上时,扫描文件就非常耗费时间,有时还会出现只是很少一部分数据发生了变化,因此rsync就变得非常低效了。其次,rsync不能够实时监测、同步数据,虽然它可以通过Linux守护进程的方式触发同步,但是两次触发动作一定会出现时间差,可能导致服务器端和客户端的数据出现不一致,后期无法在出现故障时完全恢复数据。 Rsync+inotify组合 为解决以上问题而出现的,实现了数据的实时同步 inotify是什么 ? inotify是一种强大的、细粒度的、异步的文件系统事件监控机制,Linux内核从2.6.13版本起,加入了对inotify的支持。通过inotify可以监控文件系统中添加、删除、修改、移动等各种事件,利用这个内核接口,inotify-tools便可以监控文件系统下文件的各种变化情况了。 检查内核是否支持inotify: 实验案例:rsync

inotify

匿名 (未验证) 提交于 2019-12-03 00:22:01
inotify工具包有2个重要命令 inotifywatch:使用Linux的inotify接口监听文件系统事件,并输出统计文件或目录接收到的事件 inotifywait:使用Linux的inotify接口高效的监控文件状态是否改变,非常适合搭配shell脚本监控文件 inotifywait命令 格式:inotifywait [-hcmrq] [-e <event> ] [-t <seconds> ] [--format <fmt> ] [--timefmt <fmt> ] <file> 常用的选项: 选项 作用 -m, --monitor 始终保持事件的监听状态 递归查询目录 -q, --quiet 只打印监控的事件信息 排除文件或者目录,不区分大小写 -t <seconds>, --timeout <seconds> 超时时间 -e <event>, --event <event> 监听指定事件,有几个常见的事件如下 以可写方式打开的文件被关闭 moved_from 文件从目录移动 移动文件或目录移动到监视目录 在监视目录下创建文件或目录 --timefmt <fmt> 自定义时间输出格式 常用的时间格式: --format <fmt> 自定义inotifywait的输出格式, 或目录信息,否则为空 开 --timefmt 选项的语法格式进行设置 示例1:监控

监控文件事件

匿名 (未验证) 提交于 2019-12-03 00:08:02
1.作用:   对 文件或目录 进行监控,探测是否发生特定事件。 2.相关api int inotify_init ();   创建监控实例,返回句柄。 int inotify_add_watch ( int fd , const char * pathname , uint32_t mask );   添加监控事件,返回监控描述符。   注意:inotify_add_watch对文件有一次性读操作,所以需要有读权限。 int inotify_rm_watch ( int fd , uint32_t wd );    删除监控项 3.inotify_event struct inotify_event { int wd ; // 监控描述符 uint32_t mask ; //事件 uint32_t cookie ; // 相关事件,只用于重命名 uint32_t len ; //name域长度 char name []; //可选的以null结尾的字符串 }      使用read可以获得一个或多个event。   如果read的buf不足一个event,则失败,返回EINVAL.   read buf的最小长度 sizeof(struct inotify_event) + MAX_NAME_LEN + 1   inotify是一个环形队列,所以可以描述事件发生顺序。