I'm writing a script which checks for the space in the server and deletes the Old backup/'s is the space is less than 2 GB . The Script is working fine , but as i'm using use strict; use warnings; in my script for my practise purpose this error is thrown out .
Here is the script
#!/usr/bin/perl
use strict;
use warnings;
my @backups;
my $now=time();
my $dayago=10;
my (@space,@freesp);
@space=grep /\/dev\/md0/,`df`;
for(@space){
chomp;
@freesp=split /\s+/ ,$_;
}
chdir '/home/ftpusr/backup' or die "Can't cd to backup dir: $!\n";
while (($freesp[3]/1024/1024 < 2.0) && ($dayago > 0)){
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now-$dayago*60*60*24);
my $today_timestamp=sprintf("%4d%02d%02d",$year+1900,$mon+1,$mday);
@backups = glob("*NODE0000.CATN0000.$today_timestamp*");
#print "@backups\n";
$dayago -= 1;
#print "$dayago\n";
unlink ($backups[0]);
}
I have initialized $dayago parameter to 10 so that it checks for backup from last 10 days and comes near to current date , so as far as i understood for the 1st iteration of while loop its did not find the specific file with the timespace so it could not inlink so throwed up this warning . Is there any way can i eliminate this warning ?
Here is the O/P when i run the script
9
Use of uninitialized value in unlink at purge3.pl line 26.
8
Use of uninitialized value in unlink at purge3.pl line 26.
7
Use of uninitialized value in unlink at purge3.pl line 26.
6
Use of uninitialized value in unlink at purge3.pl line 26.
5
Use of uninitialized value in unlink at purge3.pl line 26.
4
Use of uninitialized value in unlink at purge3.pl line 26.
GSRTC.0.db2inst1.NODE0000.CATN0000.20130315102900.001
3
GSRTC.0.db2inst1.NODE0000.CATN0000.20130316150941.001 GSRTC.0.db2inst1.NODE0000.CATN0000.20130316171526.001
2
1
Use of uninitialized value in unlink at purge3.pl line 26.
GSRTC.0.db2inst1.NODE0000.CATN0000.20130318095532.001
0
And the files in the directory will be listed like which i need to delete them
GSRTC.0.db2inst1.NODE0000.CATN0000.20130315102900.001
GSRTC.0.db2inst1.NODE0000.CATN0000.20130316150941.001
GSRTC.0.db2inst1.NODE0000.CATN0000.20130318095532.001
AWDRT.0.db2inst1.NODE0000.CATN0000.20130319092156.001
GSRTC.0.db2inst1.NODE0000.CATN0000.20130319095258.001