I am running a perl script. In my perl script, I check the current date and the folder name(which is also in the date format like for example 11-12-07). This perl script run automatically when It checks the curent date with the folder name. The folder is a tar folder which is loaded from other server.
So, basically I need to run the script if it matched with the folder name and current date.
Problem: Sometimes, I used to get the folder next day and my perl script checks only for the current date. The folder i get has the name which is previous date (not the current date).So, I need to do processing of the folder manually. I need to automate it in my perl script.
Please suggest me some ideas to make it happen.
Thanks!!
Code for Reference:
my $tfilename = 'tarmd5.tar';
my $td = `date '+%y-%m-%d'`; # date in yy-mm-dd format
chomp ($td);
my $td2 = `date '+%Y%m%d'`; # date in yyyymmdd format
chomp ($td2);
#
# get directory from command line
$dir = shift;
leave("'$dir' is not a valid directory") unless (-d $dir);
if ($dir eq '.') {$dir = cwd();}
elsif ($dir !~ /^\//) {$dir = cwd()."/$dir";}
# print out the time
print scalar(localtime()),"\n";
######## This section unpacks transferred data ########
# go to directory for today and find *tar.gz files to copy
my $dday = "$dir/$td";
next unless (-d "$dday");
@gzfiles = glob("$dday/*tar.gz");
foreach $zf(@gzfiles) {
next if (($zf =~ /BMP/) || ($zf =~ /LG/) || ($zf =~ /MAP/) || ($zf =~ /STR/));
print "$zf\n";
($status,$message) = systemcall("/bin/cp $zf $fdir");
}
Maybe using DateTime to do the math. I redid the solution as the first was poorly written. Changed
DateTime->todaytoDateTime->nowbecause one wants the hms portion when converting back to the desired time zone (from ‘floating’ or ‘UTC’).Also used Perl functions instead of shelling out to the Unix system, (date functions, current working directory – cwd, and copy function).
Update:
elsif ($dir != /^\//)is incorrect. Changed toelsif ($dir !~ /^\//).