如何使用 dnotify/inotify 命令持续监控目录 [英] How to continuously monitor the directory using dnotify /inotify command

查看:15
本文介绍了如何使用 dnotify/inotify 命令持续监控目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 dnotify/inotify 命令的新手.任何人都可以帮助我如何编写一个脚本,使其持续监视目录并指示对其进行了一些更改或修改.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆