Find out whether directory has been updated with files in the last 5 minutes or not

Hi,

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.

Thanks for any help provided, in advance !!

In that case, better to post the OS info and shell version first.

I am using ksh

Please post the output from these commands, blocking anything confidential (like machine names) with X's:

uname -a
echo "${SHELL}"

Are you able to use the root login?

$ uname -a
SunOS XXXX 5.10 Generic_147440-13 sun4v sparc SUNW,T5440

$ echo "${SHELL}"
/bin/ksh

No, I have only limited privileges to the server - can't login as root

Try to read about this:
Solaris - stat(1)

AFAIK there is also possibility to use FAM.

1 Like

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 Like

Thanks methyl - The solution worked out perfectly :slight_smile:

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.

Thanks again for any suggestions provided.

find lets you reverse logic with !. So instead of -newer , '!' -newer

2 Likes