quick hacks

copy files from a directory to a destination by number offset:

 

#!/usr/bin/perl -w

use strict;
use Getopt::Std;
use File::Copy;

my %opts = ();
getopts('d:n:f:', \%opts);

my $dir = $opts{d};
my $num = $opts{n};
my $frm = $opts{f};
my $to_dir = '/var/log/'.$dir;

die "no directory : [$dir]\n"  unless -d $dir;
die "no files specified : [$num] (must be a number)\n" unless $num =~ m/^\d+$/;
if(defined($frm)) {
  die "no offset specified : [$frm] (must be a number)\n" unless $frm =~ m/^\d+$/;
}

print “processing dir :[$dir]\n”; print “files :[$num]\n”; print”reading dir ….\n”; opendir(DIR, $dir) || die “can’t opendir $dir: $!”; my @files = grep { ! /^\./ && -f “$dir/$_” } readdir(DIR); closedir DIR; print”dir read ….\n”; my $from = $frm || 0; print”>>DEBUG>>from:[$from]\n”; for (0 .. ($num – 1)) { $_ += $from; print”copying file:[$dir/$files[$_]] => $to_dir\n”; copy(“$dir/$files[$_]”, $to_dir) or die “copy failed : $!\n”; } __END__

Lascia un commento

Il tuo indirizzo email non sarĂ  pubblicato. I campi obbligatori sono contrassegnati *