Shell script: If a file stays in a particular directory more than 30 min send an email

Hi ,
I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab.
can anyone help me?

What OS?

Hi ,
Thanks for the reply.it's solaris 5.8

try this...

find ./ -name <your_file_name> -cmin +30 -maxdepth 1 -exec mailx -s "file 30 minutes old" you@mail.com {} \;

This is i am using in file2.unx
find /home/dbaprod/test -name file1.unx -cmin +5 -maxdepth 1 -exec mailx -s "file 5 minutes old" muraliinfy04@gmail.com {} \;

this is crontab entry
02 * * * * /home/dbaprod/test/file2.unx >>/tmp/exception 2>&1

but i am not getting output.mailx is working...actually i need to check the file time when it received in the folder.if it is stays more than 30 min in that folder i need to receive a mail..can any one help me in this...it's urgent...

you can try this

 
find /home/dbaprod/test -name file1.unx -cmin +5 -maxdepth 1 -exec ls -lh {} \; > listfile ; mailx -s "file 5 minutes old" muraliinfy04@gmail.com < listfile

-rw-r--r-- 1 dbaprod other 0 Mar 29 04:05 listfile

with that command nothing is recorded in list file..can anyone help me in this

Help yourself some here, check the man page for the 'find' command. the 'cmin' argument is looking at last_changed_time and what ever process is putting the file in the directory may be keeping it's original time. There are arguments for last modified time, last accessed time, etc. Also run just the find command and see if it finds the file first. Then you can work out the email part. Keep in mind that the cron process has a limited shell and you may need to setup the PATH variable in your script to get 'find' and 'mailx' working from within a cron executed script.

I bet my money on the "cron error nr. 1": your script fails to set any environment and takes the environment of your login shell for granted - but it isn't. Since mailx (and find, and anything else) is not in the PATH it isn't "working", but missing.

bakunin