在受监视的目录中发送有关文件更改的电子邮件 [英] Send E-Mail on File Change in monitored directory

查看:68
本文介绍了在受监视的目录中发送有关文件更改的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果服务器上他们的职员文件夹中的文件发生更改,我想向我们公司的家伙发送电子邮件通知。
我有一个脚本,可以使用inotifywait在每次文件更改时发送电子邮件,效果很好。
我想做的是上传多个文件(假设10张jpg正在上传到某人的工作人员文件夹),只发送一封电子邮件。

I want to send an e-mail notification to guys in our company if a file changed in their staff folder on the server. I have a script that works fine on sending an e-mail on every file change using inotifywait. What I would like to do is on multiple file uploads (lets say 10 jpg's are being uploaded to somebody's staff folder) to only send out one email.

此脚本会在每次文件更改时发送电子邮件:

This script sends an email on every file change:

inotifywait --recursive --exclude '.DS_Store' -e create -e moved_to -m /media/server/Staff/christoph |
    while read path action file ; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
        sendEmail -f server@email.com -t user@gmail.com -s smtpout.secureserver.net:80 -xu user@email.com -xp password \
         -u ""The file $file appeared in your directory"" -m ""To view your file go to $path""
done

最聪明的方法是什么?让inotify等待2分钟的进一步输入是否有意义?

What is the smartest way to go about this? Does it make sense to have inotify wait for further input for lets say 2 mins?

BTW我正在为此使用sendemail,因为端口25被ISP阻止了。 / p>

BTW I'm using sendemail for this since port 25 is blocked by the ISP.

推荐答案

我可能会通过将修改通知写入文件来实现此目的(如果我这样做的话,我可能会使用SQLite数据库),然后每隔几分钟运行一次cron作业以检查数据库并发送汇总的电子邮件。

I would likely do this by writing the modification notices to a file (if I was doing it I would probably use a SQLite database), then run a cron job every few minutes to check the database and send an aggregated email.

另一种选择是使用inotifywait触发脚本来观看该特定事件文件,它只会循环检查文件的大小/修改时间,然后休眠一段时间。文件停止增长后,脚本会将文件信息附加到消息文件中。 cron作业将发送消息文件(如果不为空),然后截断该文件。这样可以避免从日志文件读取和写入数据。

Another option would be to use inotifywait to trigger a script to watch that specific file, it would just loop checking the size/modified time of the file, then sleep for some period of time. Once the file stopped growing you the script would append the file info out to a message file. The cron job would send the message file (if it was not empty) then truncate the file. This would avoid the need to read and write data from a log file.

这篇关于在受监视的目录中发送有关文件更改的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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