I am trying to work on this script that needs to monitor a Directory.
In case there are no files received in that Directory for the last 5 minutes, it has to send out an alert.
Could someone please suggest any approach for the same.
Note: I did check out various previous psts - However, the Unix I am using does not support various command : like find -mtime, etc.
Your O/S does support "find -mtime" but not "find -mmtime".
Basic technique is to set up a cron to run every 5 minutes during the period of the day you want to run this monitor (but starting 5 minutes before the first time you want to monitor).
Script uses "find -newer" against a marker file and changes the timestamp of the marker file after each check.
#!/bin/ksh
if [ ! -f /var/tmp/junk/marker ]
then
touch /var/tmp/junk/marker
exit
fi
found=`find /path/directory -type f -newer /var/tmp/junk/marker -print | wc -l`
if [ ${found} -gt 0 ]
then
echo "Files found"
else
echo "No files found"
fi
touch /var/tmp/junk/marker
We'll leave you to decide what "send out an alert" means.
1 more question ---- Is there any option to find out the reverse as well - to find files which are there in the directory for more than 5 minutes.
So the check should be on whether there are any files in the directory with lesser timestamp than marker.