Linux利用inotify-tools的inotifywait实现:当文件夹内容改变时自动执行一段脚本

本文介绍了如何借助inotify-tools的inotifywait工具,在Linux系统中实现实时监控文件夹内容变化,并在发生变化时自动执行预设的脚本进行相应操作,例如在新的rpm包存入指定目录时进行检测。
摘要由CSDN通过智能技术生成

当我在建一个rpm包管理服务器时,里面有个这样的要求,要求当有新的rpm存入指定目录时,自动执行一段脚本去对这个rpm包进行检测。

这里利用了inotify-tools的inotifywait的模块,里面有个事件处理的参数-e,见它的手册。

我的代码如下:

#/bin/bash
################################################################
#  automatically run a script(action.sh) when the contents
#     of a directory (${EVENTPATH}) changed.
#  pls. install the inotify-tools-3.13-1.el4.rf.i386.rpm module
#       before use this scripts
#  Aborn Jiang (aborn.jiang@gmail.com)
#  Sep.8, 2013
################################################################

EVENTPATH="."
MSG=".inotifymsg"
PATTERN=".rpm$"          # only when the rpm files changed.
while inotifywait -e modify -e create -e delete -e moved_to -e moved_from \
                   ${EVENTPATH} 1>${EVENTPATH}/$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值