Thanks Rob Dixon and John W. Krahn for your help I really appreciate it.
This is what I came up with based on your examples and the code works
great. Thanks again. 

 

Rob McGinness

 

#!/usr/bin/perl

 

my $dir = "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives/";

my $dh = opendir DIR, ".";

 

my @files = do {

        opendir my $dh, $dir or die "Cannot open '$dir' $!";

        grep /^Completed\.archive\.\d{1,4}$/

        && -M "$dir/$_" > 7, readdir $dh; };

 

foreach (@files) {

 

        system ("compress -v "."$dir".$_);

#       print "$_\n";

 

};

 

# This code will compress log files that contain the name of 

# "Completed.archive.[number]" that are older than 7 days and exluding
all other files # that have already been compressed ex.
Completed.archive.7.Z.  This will ensure that # the most recent log file
that is currently in use will not be compressed.

 

 

 

 

 

 

-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2008 10:44 AM
To: Perl Beginners
Cc: John W. Krahn
Subject: Re: Using a Perl script in AIX / Unix

 

 

John W. Krahn wrote:

> Rob Dixon wrote:

>> Rob McGinness wrote:

>>> die unless chdir

>>> "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives";

>>> 

>>> die unless opendir DIR, ".";

>> I suggest you write something like the program below.

>> 

>> 

>> #!/usr/bin/perl

>> use strict;

>> use warnings;

>> 

>> my $dir = "/cert/ImpactServer-5_4/cl9/ctrl_sfm9/sfm9_sched/archives";

>> 

>> my @files = do {

>>   opendir my $dh, $dir or die $!;

>>   grep /^Completed\.archive\.\d{1,4}$/, readdir $dh;

>> };

>> 

>> @files = sort grep -M > 7, @files;

> 

> The OP chdir()ed to the directory in question so the files were in the


> current directory, however your code does not so the -M test will not 

> work unless you prepend the directory name to the file name:

> 

> @files = sort grep -M "$dir/$_" > 7, @files;

> 

> 

> Also, why not put both tests in the first grep:

> 

> my @files = do {

>    opendir my $dh, $dir or die "Cannot open '$dir' $!";

>    grep /^Completed\.archive\.\d{1,4}$/

>         && -M "$dir/$_" > 7, readdir $dh;

> };

> 

> 

>> foreach (@files) {

>>   system 'compress', '-v', $_;

>> }

> 

> You should verify that system worked correctly:

> 

> foreach (@files) {

>    0 == system 'compress', '-v', $_ or die "system 'compress' failed:
$?";

> }

 

Thanks John

 

-- 

To unsubscribe, e-mail: [EMAIL PROTECTED]

For additional commands, e-mail: [EMAIL PROTECTED]

http://learn.perl.org/ 
  
  
This message (and any included attachments) is from Rutland Regional Health 
Services and is intended only for the addressee(s). The information contained 
herein may include privileged or otherwise confidential information.  
Unauthorized review, forwarding, printing, copying, distributing, or using such 
information is strictly prohibited and may be unlawful. If you received this 
message in error, or have reason to believe you are not authorized to receive 
it, please promptly delete this message and notify the sender by e-mail. 
 Thank  You 

Reply via email to