一个程序来监视Linux上的目录 [英] a program to monitor a directory on Linux

查看:132
本文介绍了一个程序来监视Linux上的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有就是一个哥们增添了新的目录中建立一个产品。

上市看起来像这样

  $ LS路径到目录/
01
02
03
04
$

在这里列出的号码不包含建立目录的文件,但名称。

我必须手动去检查每一个是否有新的版本或没有时间。 我要寻找一种方式来自动执行此,使程序可以发送电子邮件到一些人(包括我)只要路径到目录/ 更新


  • 我们有一个已经存在的工具或Perl库,这是否?

    inotify.h 有类似的功能,但它不支持我的内核(2.6.9)。


我觉得有可能是在Perl一个简单的方法。


  • 你觉得这是否行得通呢?


      

    请运行在Perl一个循环,做了 LS路径到目录/ 之后,也就是说,每5分钟,并将结果存储在数组中。如果发现新的结果是从旧的结果不同,它发出使用邮件或的电子邮件




解决方案

检查不同的 LS 输出甚至会在一些被删除或目录改名发送消息。你可以代替查找文件比发送的最后一条消息一个新的mtime。

下面是在bash一个例子,你可以运行它每隔5分钟:

 目前=`日期+%Y%M%D%H%M.%S`如果[! -f/路径/要/缓存/文件] || [-n`找到/路径/要/编译/ DIR型的F -newer /路径/要/缓存/ file`]
然后
    触摸/路径/要/缓存/文件-t$现在的
    sendmail的-t<<<
要:aaa@bbb.ccc
要:xxx@yyy.zzz
主题:新发现的文件亲爱的朋友,
我已经找到了一些新的文件。

科幻

There is a directory where a buddy adds new builds of a product.

The listing looks like this

$ ls path-to-dir/
01
02
03
04
$

where the numbers listed are not files but names of directories containing the builds.

I have to manually go and check every time whether there is a new build or not. I am looking for a way to automate this, so that the program can send an email to some people (including me) whenever path-to-dir/ is updated.

  • Do we have an already existing utility or a Perl library that does this?

    inotify.h does something similar, but it is not supported on my kernel (2.6.9).

I think there can be an easy way in Perl.

  • Do you think this will work?

    Keep running a loop in Perl that does a ls path-to-dir/ after, say, every 5 minutes and stores the results in an array. If it finds that the new results are different from the old results, it sends out an email using Mail or Email.

解决方案

Checking for different ls output would send a message even when something is deleted or renamed in the directory. You could instead look for files with an mtime newer than the last message sent.

Here's an example in bash, you can run it every 5 minutes:

now=`date +%Y%m%d%H%M.%S`

if [ ! -f "/path/to/cache/file" ] || [ -n "`find /path/to/build/dir -type f -newer /path/to/cache/file`" ]
then
    touch /path/to/cache/file -t "$now"
    sendmail -t <<< "
To: aaa@bbb.ccc
To: xxx@yyy.zzz
Subject: New files found

Dear friend,
I have found a couple of new files.
"
fi

这篇关于一个程序来监视Linux上的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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