监视文件夹树的变化,并在创build文件时运行脚本 – linux

我正在尝试创build一个运行shell脚本的后台,它会在文件树中创build文件时检查文件名是否符合特定条件,然后将其移动。

应用程序 – 通过电子邮件发送FreePBX电话录音。

文件存储在/ var / spool / asterisk / monitor / yyyy / mm / dd /

例如 – / var / spool / asterisk / monitor / 2014/07/10 / conf-220-220 …

因此创build录制文件时,会根据文件名检查是否发送给谁,并通过电子邮件将其移出文件夹。

我看到了关于inotify-tools的build议,但是网站上的最新消息是从2010年开始的。

我也看到incron,但想要有一个小的机会弄乱我的电话系统的东西(我害怕安装程序)

inotify.aiken.cz/?section=incron&page=doc&lang=en

由于此版本较早,因此不包含标准的可移植构build机制(如autotools)。 只有一个Makefile必须手动修改。 在许多Linux系统上,你不需要改变任何东西。

inotify正在一段时间,这是稳定的,是许多发行主流的一部分。

如何安装:

在Ubuntu上:

sudo apt-get install inotify-tools

在Centos / RHEL上(来自EPEL回购):

yum --enablerepo epel install inotify-tools

如何使用:

 inotifywait -re create /tmp/test1/ && echo "Change detected" 

一旦你创建一个文件echo "change detected"将被触发,这可能是几乎任何东西。

你得到的输出:

 Setting up watches. Beware: since -r was given, this may take a while! Watches established. /tmp/test1/test2/test3/ CREATE file Change detected 

PS。 -r递归-e create来检测新文件。