I am looking for a script which will work as a watch directory.
I ha directory which keep getting files in every 10 mins and some time delay.
I want to monitor if the directory getting the files in every 10 mins if not captured the last received file time and calculate the delay.
So every 10 minutes, check the directory and if the most recent file is greater than 10 minutes old send a mail with the subject "No new files seen since ${LATEST_FILE_TIMESTAMP}"
You can use cron to run the check every 10 minutes.
and the rest could be acomplished with something like the following:
if [ $(( $(date +%s ) - $(stat -t $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}') )) - gt 600 ]; then #
mailx -S "No NEW FILES SEEN SINCE $(date --date=@$(stat -t $(ls -lrt ${PATH_TO_RECEIVING_DIRECTORY}| tail -1 | awk '{print $NF}') | awk '{print $13}' )" sadique.manzar@unix.com
fi
Why not check the modified date of the directory itself? With the assumption that nothing else is going on there (any maintenance to be considered separately), it should represent the last file's arrival. Try
cd ${PATH_TO_RECEIVING_DIRECTORY}
if (( ( $(date +%s) - $(stat -c%Y .) ) > 600 )); then echo "overdue file"; else echo "file in time"; fi
cd BACK_TO_WHERE_YOU_CAME_FROM