我是 dnotify/inotify 命令的新手。任何人都可以帮助我如何编写一个脚本,以便它持续监视目录并指示它有一些更改或修改。
Inotify 本身是一个内核模块,可以通过调用来访问,例如一个 C 程序。
https://linux.die.net/man/7/inotify https://linux.die.net/man/7/inotify
有一个名为 inotify-tools 的应用程序套件,其中包含:
inotifywait - 使用 inotify 等待文件更改
http://linux.die.net/man/1/inotifywait http://linux.die.net/man/1/inotifywait
and
inotifywatch - 使用 inotify 收集文件系统访问统计信息
http://linux.die.net/man/1/inotifywatch http://linux.die.net/man/1/inotifywatch
您可以直接从命令行使用 inotify,例如像这样持续监视主目录下的所有更改(可能会生成大量输出):
inotifywait -r -m $HOME
下面是一个持续监控 Apache 日志活动并对其做出反应的脚本,该脚本是从 inotifywait 的 man 文件复制的:
#!/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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)