What I need to do is wrote a script that will read in a list of directories and then sort them and the last directory will be "poped" off.
my $last_one = pop @sorted;
Then that last directory is going to be removed - with a system("rm- rf $last_one) or remove_tree($last_one).
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $dir_to_process = "/production/log/fo/archive/";
6 opendir DH, $dir_to_process or die "Sorry, this is not going to work out $!";
7
8 while (my $name = readdir DH) {
9 next if $name =~ /^\./;
10 push(my @unsorted,$name) ;
11 my @sorted_dir = sort @unsorted;
12 foreach my $sorted (@sorted_dir) {
13 print "$sorted\n";
14 sleep 1 ;
15 }
16
17 }
However I am having alot of trouble sorting the directories - they are written by this format. This is the actual output.
2013Nov12
2013Sep14
2013Jul15
2013Jan20
2013Sep11
2013May31
2013Jul04
2012Dec09
2013Oct12
2013Oct09
2012Dec27
2013Nov28
2013Mar24
2013Jun06
2013Jun25