unix下shell程序备份系统关键信息
#!/usr/local/bin/perlmy $choice = shift;
my @files = @ARGV;
my @selection;
if ($choice =~ /thismonth/)
{
my ($day,$mon,$year) = dateaslist();
my $match = sprintf('%04d%02d',$year,$mon);
foreach my $file (@files)
{
if ($file =~ m/$match/ && $choice eq 'thismonth')
{
push @selection,$file;
}
elsif ($file !~ m/$match/ && $choice eq 'notthismonth')
{
push @selection,$file;
}
}
}
elsif ($choice =~ /today/)
{
my ($day,$mon,$year) = dateaslist();
my $match = sprintf('%04d%02d%02d',$year,$mon,$day);
foreach my $file (@files)
{
if ($file =~ m/$match/ && $choice eq 'today')
{
push @selection,$file;
}
elsif ($file !~ m/$match/ && $choice eq 'nottoday')
{
push @selection,$file;
}
}
}
elsif ($choice =~ /last(\d+)days/)
{
my $days = $1;
my ($day,$mon,$year) = dateaslist(time()-($1*24*3600));
my $match = sprintf('%04d%02d%02d',$year,$mon,$day);
my $spec = sprintf('last%ddays',$days);
my $notspec = sprintf('notlast%ddays',$days);
foreach my $file (@files)
{
my ($date) = ($file =~ m/(\d{8})/);
push @selection,$file if ($date >= $match && $choice eq
$spec);
push @selection,$file if ($date < $match && $choice eq
$notspec);
}
}
print join ' ',@selection;
sub dateaslist
{
my ($time) = @_;
$time = time() unless defined($time);
my ($day,$mon,$year) = (localtime($time));
$mon++;
$year+= 1900;
return($day,$mon,$year);
}
页:
[1]