Hi all,

Am wanting to get some advise on how to write this Perl script.

I have a backup directory that I have to check for the existence of file/s
and if the latest file that exist there is 2 days old, that means I have a
problem and had to send an email notification.

To illustrate if, for example, a directory named /backup have the following
files and their timestamps:

/backup/file.01 01-Jan-2011 0500
/backup/file.02 02-Jan-2011 0500
/backup/file.03 03-Jan-2011 0500
......
......
/backup/file.31 31-Jan-2011 0500
/backup/file.32 01-Feb-2011 0500
/backup/file.33 02-Feb-2011 0500

I want the script to check the most recent file in a backup directory, i.e.
newest, for example /backup/file.33 and display the timestamp, i.e. date and
time, of the file. Then I want to compare it with today's date and display
the date/time difference in n days n hours n minutes. If the file is more
than 2 days old, that should mean that the backup did not run so I have to
send an email notification.

So for example, if today is 04-Feb-2011 1000 0800 and there is no backup
file created on 03-Feb-2011, when the script runs, it should detect that the
most recent backup file is file.33, "computed" that it is older than 2 days
and then send en email notification.

Sample output from the script should be as below:

===================================================

Checking last backup file on 04-Feb-2011 10:05:
   Last backup file = /backup/file.33
   Timestamp = 02-Feb-2011 05:00
   The file is = 2 days 5 hour/s 5 minute/s old
   Send email notification to check backup

===================================================

My main hurdle is the file timestamp and date arithmetic part. Frm
Google'ing, am leaning towards using stat which am hoping will work on both
Unix and Windows.

Some guidance will be much appreciated. Thanks in advance.

Reply via email to