The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 4,917β€…    Votes:  2β€…
Tags: command-line   bash   scripts  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1157136
Title: How I can monitor for new files in a directory and drop a mail if files are not added every 30 mins?
ID: /2019/07/09/How-I-can-monitor-for-new-files-in-a-directory-and-drop-a-mail-if-files-are-not-added-every-30-mins_
Created: July 9, 2019
Upload: March 26, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


The answers so far assume that files only go into a directory and never go out. But what if you have a script that empties the directory periodically? Then the script could miss the fact a file went into the directory 5 minutes ago but was processed and taken out.

Another option is using the inotifywait command written in highly efficient C language for the express purposes of monitoring file and directory creation and modification. You can install it with the command:

sudo apt install inotify-tools

The psuedo-code for an appropriate script would be:

You would call the script from a place like /etc/rc.local so it runs when machine is booted.

The advantage of this methodology is you aren’t checking the directory every 30 minutes but rather you are checking it 30 minutes after the last changes to the directory.

⇧ Should I now upgrade Ubuntu 16.04 LTS? Ubuntu show grub boot menu and do not auto boot?  β‡©