Computing.Net > Forums > Unix > Recent File List - AIX

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Recent File List - AIX

Reply to Message Icon

Name: delory
Date: January 15, 2004 at 09:42:06 Pacific
OS: AIX
CPU/Ram: 700 256
Comment:

I need to run script from a cron to check if any new files have arrived in a directory since the script last ran and mail a user. Is there an easy way to do this?

Many thanks in advance for your time.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: January 15, 2004 at 11:16:21 Pacific
Reply:

Each time your cron job runs, it can update the date stamp on a control file which allows it to remember when it ran last.  The controlfile and the output list of files should not be in the directory where you are checking for recent files because they would always end up quailifying as recent files.

Using "find -newer", we will find all files with a recent date stamp (since the last cron execution), and that could include new files or old files that have been recently modified.  If you want new files only, and not old files that have already been processed but now have a recent date stamp, you will need a more sophisticated approach.

The first cron execution will not find any files because there is no control file yet, but that first execution will create a control file.

Your mail command would include /home/recentfiles in the e-mail body.

find . -type f -newer /home/laststamp > /home/recentfiles

if [ -s /home/recentfiles ] ; then
   echo 'recent files found - need to send e-mail here'
else
   echo 'no recent files found'
fi

touch /home/laststamp

One little problem: If any new files arrive after the "find" begins and before updating the control file with the touch command, those files would get missed.  Therefore, a safer approach would be:

touch /home/newstamp
find . -type f -new /home/laststamp
(process recent files, such as send e-mail)
mv /home/newstamp /home/laststamp


0

Response Number 2
Name: delory
Date: January 20, 2004 at 01:58:12 Pacific
Reply:

Worked perfectly, thank you.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


awk/nawk field assignment... 2 NewB questions



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Recent File List - AIX

Script to create a file listing www.computing.net/answers/unix/script-to-create-a-file-listing/5850.html

transfering files form Aix unix to www.computing.net/answers/unix/transfering-files-form-aix-unix-to-/3697.html

Tar a file on AIX & untar on OS/390 www.computing.net/answers/unix/tar-a-file-on-aix-amp-untar-on-os390/7696.html