编译安装inotify-tools和监控inotifywait事件

                 编译安装inotify-tools软件包

1)解包inotify-tools-3.13.tar.gz文件

[root@svr7~]#ls inotify-tools-3.13.tar.gz

inotify-tools-3.13.tar.gz

[root@svr7~]#tar xf inotify-tools-3.13.tar.gz-C/usr/src/

2)配置./configure,安装目录默认(/usr/local/*/

[root@svr7~]#cd /usr/src/inotify-tools-3.13///进入源码目录

[root@svr7 inotify-tools-3.13]#./configure//配置操作

checking for a BSD-compatible install.../usr/bin/install-c

checking whether build environment is sane...yes

checking for gawk...gawk

....

configure:creating./config.status

config.status:creating Makefile

....

[root@svr7 inotify-tools-3.13]#ls Makefile//检查配置结果

Makefile

3)编译make

[root@svr7 inotify-tools-3.13]#make

....

Making all in src

make[2]:Entering directory`/usr/src/inotify-tools-3.13/src'

make[3]:Entering directory`/usr/src/inotify-tools-3.13'

make[3]:Leaving directory`/usr/src/inotify-tools-3.13'

....

4)安装make install

[root@svr7 inotify-tools-3.13]#make install

....

/usr/bin/install-c.libs/inotifywait/usr/local/bin/inotifywait

/bin/sh../libtool--mode=install/usr/bin/install-c'inotifywatch''/usr/local/bin/inotifywatch'

....

[root@svr7 inotify-tools-3.13]#find /usr/local/ -name "inotify*"

/usr/local/bin/inotifywait//确认安装结果

/usr/local/bin/inotifywatch

/usr/local/include/inotifytools

/usr/local/include/inotifytools/inotifytools.h

步骤三:测试inotify-tools软件程序

软件包inotify-tools提供了一个主要程序inotifywait,可以用来监控指定目录或文档的变化,并及时给出通知。

1)开启对/opt目录的事件监控

[root@svr7~]#inotifywait -mrq  /opt& //开启监控

[1]15568

2)修改/opt/目录内容,观察屏幕输出信息

[root@svr7~]#touch /opt/a.txt//新建文件a.txt

/opt/CREATE a.txt

/opt/OPEN a.txt

/opt/ATTRIB a.txt

/opt/CLOSE_WRITE,CLOSE a.txt

[root@svr7~]#mv /opt/a.txt /opt/b.txt//将文件改名

/opt/MOVED_FROM a.txt

/opt/MOVED_TO b.txt

3)结束inotifywait监控

杀死当前用户的第一个后台任务:

[root@svr7~]#kill -9 %1

[1]+Killed inotifywait-mrq/opt

posted @ 2019-11-26 16:42  云计算(互联网)  Views(1480)  Comments(0Edit  收藏  举报