On 3/2/11 Wed Mar 2, 2011 8:34 AM, "newbie01 perl" <newbie01.p...@gmail.com> scribbled:
> 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. The file test operator -M, when applied to a file, will return the age of the file in days. Thus, you can use a test such as if( -M $filename > 2 ) to determine if a file is more than 2 days old. See: perldoc -f -X -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/