How to continuously monitor the directory using dnotify /inotify command

后端 未结 3 1376
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 03:43

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 modi

3条回答
  •  春和景丽
    2020-11-29 03:52

    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/

    There is an application suite called inotify-tools, which contains:

    inotifywait - wait for changes to files using inotify

    http://linux.die.net/man/1/inotifywait

    and

    inotifywatch - gather filesystem access statistics using inotify

    http://linux.die.net/man/1/inotifywatch

    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
    

    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
    

提交回复
热议问题