监控文件夹。没有活动1小时,发送电子邮件 [英] Monitor a folder. no activity for 1 hour, send an email

查看:57
本文介绍了监控文件夹。没有活动1小时,发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试制作一个脚本来监控文件大约每5分钟传递一次的目录但有时文件可能不会进来几个小时


所以脚本的目的是监视是否在1小时内没有文件通过发送电子邮件。


因此,我想使用shell命令来获取文件进入并写入txtfile的时间。

现在,当文件不断出现时,它将覆盖旧时间。

现在,如果一小时内没有新文件出现,我得到了旧时间,但我计算有困难小时如此触发发送电子邮件


这是我到目前为止所提出的

Hi I am trying to do a script to monitor a dir where files pass through approx every 5 mins but sometimes files may not come in for hours

So the purpose of the script is to monitor by if no files pass through in 1 hour send an email.

So was thinking to use the shell command to grab the time when a file comes in and write to a txtfile.
Now when the files keep coming it will overwrite the old time.
Now if no new files are coming in an hour i got the old time but i having trouble calculating the hour so to trigger out to send an email

this is what i came up with so far

展开 | 选择 | Wrap | 行号

推荐答案

尝试类似以下内容。如果脚本将继续运行,则没有理由将信息写入文件。只需将其保存在变量中即可。此外,甚至不需要找到文件的日期时间值,您只需要标记文件出现时的时间。无论如何,看看这个伪代码,看看它是否适用于你的目的。

Try something like the following. If the script is going to be running continuously then there is no reason to write information to a file. Just keep it in a variable. Also, it''s not even really necessary to find the datetime value of a file, you just must mark the time close to when the file appears. Anyway, take a look at this psuedocode and see if it will work for your purposes.

展开 | 选择 | Wrap | 行号


您好Miller


执行传输的脚本实际上并不连续运行。即便如此。实际上,执行传输的脚本是一个shel脚本,它具有每秒运行的cron作业。我想调用perl脚本脚本来执行监视部分,我还能用你的解决方案吗?
Hi Miller

The script that does the transfer does not actually run continuously. even thouight its close. BAsically the script that does the transfer is a shel script that has a cron job that runs every sec. I wanted to make a call to the perl script script to do the monitoring part, would i still be able to do it with your solution?


我不是米勒,但我认为我可以放心地回答,米勒的剧本几乎肯定是一个比每秒发射的cron作业更好的解决方案。如果你要经常运行它,你可能只需运行一次并让它保持不变。首先,如果您每秒重新启动一次作业,那么您实际上不能依赖于该级别的粒度安排。当我查看各种常规cron作业的日志时,我经常会看到1-5秒的变化。除此之外,请记住,每次启动作业时,都必须转到磁盘并重新加载脚本,以及磁盘上的perl解释器/编译器。如果你加载一次并让它循环和休眠,那么你几乎消除了所有多余的磁盘活动。您还可以通过将时间保留在本地变量而不是文件中来消除脚本中100%的磁盘写入。除此之外,米勒的剧本比你的更简单,更直接。


只需启动米勒的脚本(或等效的近似脚本)并让它一直运行。将其从crontab中删除并将其放入init脚本(或inittab)中。这种方式真的好多了。


最好的问候,

Paul
I''m not miller, but I think I can safely answer that miller''s script is almost certainly a better solution than a cron job that fires off every second. If you''re going to run it that frequently, you might as well just run it once and let it stay put. For one thing, if you restart the job once per second, you really can''t rely on scheduling at that level of granularity. When I look at logs for various of my standing cron jobs I often see 1-5 seconds worth of variation. Beyond that, remember that every time you start the job, it will have to go out to disk and reload the script, as well as the perl interpreter/compiler from disk. If you load it once and let it loop and sleep, then you eliminate almost all of that excess disk activity. You also eliminate 100% of the disk writes from your script by keeping the times in a local variable rather than a file. Beyond that, miller''s script is just so much simpler and more straightforward than yours.

Just start up miller''s script (or a close equivalent) and let it run all the time. Drop it from your crontab and put it in your init scripts (or inittab). It''s really a LOT better that way.

Best Regards,
Paul


这篇关于监控文件夹。没有活动1小时,发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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