如何使用dnotify/inotify命令连续监视目录 [英] How to continuously monitor the directory using dnotify /inotify command
问题描述
我是新来的通知/提示命令.谁能帮我写一个脚本,使它连续监视目录并指示对该目录进行了更改或修改.
I am new to dnotify/inotify command. Can any one help me how to write a script such that it continuously monitors a directory and indicates that there is some change or modification to it.
推荐答案
Inotify本身是一个内核模块,可通过来自例如一个C程序. http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/
Inotify itself is a kernel module accesible via calls from e.g. a C program. http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/
有一个称为inotify-tools的应用程序套件,其中包含:
There is an application suite called inotify-tools, which contains:
inotifywait-等待使用inotify更改文件
inotifywait - wait for changes to files using inotify
http://linux.die.net/man/1/inotifywait
和
inotifywatch-使用inotify收集文件系统访问统计信息
inotifywatch - gather filesystem access statistics using inotify
http://linux.die.net/man/1/inotifywatch
您可以直接在命令行中使用inotify,例如像这样持续监视主目录下的所有更改(可能会产生很多输出):
You can use inotify directly from command line, e.g. like this to continuously monitor for all changes under home directory (may generate lots of output):
inotifywait -r -m $HOME
这是一个脚本,可以连续监视并响应Apache日志活动,该脚本是从inotifywait的man文件中复制的:
And here is a script that monitors continuously and reacts to Apache log activity, copied from the man file of inotifywait:
#!/bin/sh
while inotifywait -e modify /var/log/messages; do
if tail -n1 /var/log/messages | grep httpd; then
kdialog --msgbox "Apache needs love!"
fi
done
这篇关于如何使用dnotify/inotify命令连续监视目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!