我想Pyinotify看一个模板目录,它有子文件夹,但我收到这个错误:
DIRECTORY /home/project/templates
[Pyinotify ERROR] add_watch: cannot watch /home/project/templates WD=-1
[Pyinotify ERROR] add_watch: cannot watch /home/project/templates/dir1 WD=-1
[Pyinotify ERROR] add_watch: cannot watch /home/project/templates/dir2 WD=-1
Waiting for stuff to happen...
Run Code Online (Sandbox Code Playgroud)
我找到了诸如使用unicode目录名或使用其他使用inotify的程序的答案,但每个程序都过于具体.
什么一般导致这个错误?
我想知道,是否有一种简单的方法来判断另一个实体是否有某个文件可以写入?我没有时间连续使用iNotify来等待任何当前作家完成写作.我需要做间歇性检查.谢谢.
我按照官方文档,安装了virtualenv和flask,然后python hello.py
却出现了问题:
* Running on http://127.0.0.1:5000/
* Restarting with reloader: inotify events
Traceback (most recent call last):
File "hello.py", line 9, in <module>
app.run(debug=True)
File "/home/aa/prj/env/lib/python2.7/site-packages/Flask-0.7.2-py2.7.egg/flask/app.py", line 553, in run
return run_simple(host, port, self, **options)
File "/home/aa/prj/env/lib/python2.7/site-packages/Werkzeug-0.7-py2.7.egg/werkzeug/serving.py", line 609, in run_simple
run_with_reloader(inner, extra_files, reloader_interval)
File "/home/aa/prj/env/lib/python2.7/site-packages/Werkzeug-0.7-py2.7.egg/werkzeug/serving.py", line 528, in run_with_reloader
reloader_loop(extra_files, interval)
File "/home/aa/prj/env/lib/python2.7/site-packages/Werkzeug-0.7-py2.7.egg/werkzeug/serving.py", line 436, in reloader_loop
reloader(fnames, interval=interval)
File "/home/aa/prj/env/lib/python2.7/site-packages/Werkzeug-0.7-py2.7.egg/werkzeug/serving.py", line 464, in _reloader_inotify
mask = reduce(lambda m, a: m | getattr(EventsCodes, a), mask, 0)
File …Run Code Online (Sandbox Code Playgroud) 我试图用inotify删除创建的文件,但它不起作用:
inotifywait -r --format '%w%f' -e create /test && rm $FILE
Run Code Online (Sandbox Code Playgroud)
当我在/ test中创建一个文件时,我得到了这个:
/test/somefile.txt
rm: missing operand
Try `rm --help' for more information.
Run Code Online (Sandbox Code Playgroud)
所以似乎$ FILE变量没有传递给rm命令......我怎么能正确地做到这一点?谢谢.
对于我正在编写的应用程序,我想知道哪些进程正在访问特定文件并将该信息转储到日志文件中。最后,其中一个进程将删除此文件,我也想知道它的进程名称。
我可以使用 INotify 库来监视文件访问,但它没有给我访问文件的进程名称。这也可以在 linux 上使用 Auditctl 包,但我也不能使用此选项:-(
实际上,出于某些原因,它是一个受控环境,最终客户已准备好运行程序,但尚未准备好安装新软件包或更改现有实用程序。
可以inotify用来在 [linux] 系统中可靠地记录文件吗?
我正在尝试用于inotifywait跟踪用户移动(目前使用 bash,但有人建议我迁移到脚本语言)。最终,我想在创建时将新文件添加到数据库 ( create, moved_from),在文件修改时更新数据库中的现有行 ( modify, attrib, move_to),最后在文件删除时删除一行 ( delete)。然而,我遇到了许多问题,即使是像save这样看似简单的操作,也会生成许多 inotifywait 消息。观察以下命令及其输出(注意, 的使用/home/user/仅用于示例目的):
示例 1:监听文件创建:
$ inotifywait -mr /home/user/ -e create --format %w:%f:%e:%T --timefmt %T
Run Code Online (Sandbox Code Playgroud)
触碰:
$touch test.txt
/home/user/:test.txt:CREATE:21:35:30
Run Code Online (Sandbox Code Playgroud)
用 vim 打开一个新文件,然后发出 :w 命令:
$vim test2.txt
/home/user/:test2.txt:CREATE:21:35:30
Run Code Online (Sandbox Code Playgroud)
使用 vim 打开现有文件,然后发出 :w 命令:
$vim test2.txt
/home/user/:4913:CREATE:21:35:30
/home/user/:test2.txt:CREATE:21:35:30
Run Code Online (Sandbox Code Playgroud)
用 gedit 打开一个新文件,然后点击保存:
$gedit test3.txt
/home/user/:test3.txt~:CREATE:21:35:30
Run Code Online (Sandbox Code Playgroud)
使用 gedit 打开现有文件,然后单击保存:
$gedit test3.txt …Run Code Online (Sandbox Code Playgroud) 我特意试图在2个子目录中同时观察2种不同的文件类型:
'css'子目录中 'js'子目录.styl文件类型中的.coffee文件类型
我只知道这么多bash而且我正试图让这样的东西发挥作用
while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do
# regex pattern to match the file ending
# and define it to $ending
if[ $ending == coffee ]
then
coffee -c $file
elif[ $ending == styl ]
then
stylus -c $file
fi
done
Run Code Online (Sandbox Code Playgroud)
//编辑//修改此行:
while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do
Run Code Online (Sandbox Code Playgroud)
所以现在它检查两个文件,但是如果css文件夹上没有.coffee文件,或者js中没有.styl文件,则会返回错误,表明没有找到文件.
另外我注意到当我运行这个脚本时,它返回/运行以下3次
Setting up watches.
Watches established.
./css/styles.styl
Run Code Online (Sandbox Code Playgroud) 我遇到以下情况:
稍微修改了一下之后,我注意到它在调试时运行良好。我在读取文件的行上设置了一个断点,从而增加了一点延迟。之后 - 文件被读取并且更改就在那里。
因此,添加 atime.sleep(1)或以其他方式延迟执行似乎可以解决问题。否则我会收到一个过早的 IN_CLOSE_WRITE 事件。
我想知道该事件是在提交更改并关闭文件之后还是在此之前触发。IN_CLOSE_WRITE 之后似乎没有其他相关事件。同时,文档有点棘手:
使用 IN_CLOSE_WRITE 因为如果发出,则相应文件上的所有更改都会安全地写入文件中
我提交了关于常见问题解答中措辞的错误报告,但与此同时,我想就此事获得一些额外的意见。这是应该发生的吗?什么是“道德正确”的解决方法?
所有这些都发生在 Linux Mint 15 x64 上。
所以我设置了一些代码来观看编辑的配置文件,直到我使用VIM编辑文件,然后我还必须查看重命名和创建的目录.然后我发现在路径层次结构中没有捕获更高的重命名.然后我看了一下符号链接...... gaaahhhh!
首先设置一个示例,显示一个(很多)棘手的符号链接场景:
mkdir config1
touch config1/config
ln -s config1 machine1
mkdir config2
touch config2/config
ln -s config2 machine2
ln -s machine1 active
Run Code Online (Sandbox Code Playgroud)
现在,给定一个我想要观看的像active/config这样的文件名,我可以看到如何获取inotify监视描述符:
config1/ -> watch active/ follow symlinks (watches inode for config1)
active/ -> watch active/ dont follow symlinks (watches inode for active symlink
active/config -> watch active/config (watches inode for config1/config)
Run Code Online (Sandbox Code Playgroud)
如何在machine1符号链接上添加手表?我是否需要找到一些方法来手动遍历每个符号链接为每个添加手表?怎么样?
目的是允许:
mkdir config3
touch config3/config
ln -s -f -n config3 machine1
Run Code Online (Sandbox Code Playgroud)
并且有inotify警告active/config已被重定向.目前看起来我将不得不添加一个手表:
- target file inode
- every directory inode leading to the file (to …Run Code Online (Sandbox Code Playgroud) 我是否可以在Linux上触发文件系统事件而不进行实际的文件更改?是否存在一些系统调用,其行为类似于文件的编写?这甚至可能吗?
我已经安装了NFS共享,并希望inotify在服务器站点上更改文件时在虚拟机中获取事件.
它似乎inotify不适用于NFS.是否有支持的网络文件系统inotify?
监视服务器站点上的事件很容易,但是如何在客户端上触发事件?那一刻我做的很简单touch,但那并不理想.
(用例是使用docker(boot2docker,OS X)进行本地开发.