SpaceCake has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 small troubles, historically speaking my usage of perl is under 3 months, so please indulge my ignorance. I have a srv on which I constantly via ftp receive tar files. I will need them to:
- untar
- ftp to remote host for processing
- remove untared items
- move the processed tars to another directory("old_data/")
Problem which I have with the current script is that I don't know which files are complete and which ones are just being uploaded, and I after the successful untar, move them further. Ideas ?
use Archive::Tar;
use File::Copy;
chomp(my @list=`ls data*.tar`);
foreach $file (@list) {
$tar = Archive::Tar->new;
$tar->read( $file );
$tar->extract();
UPDATE
Any chance to help me out with this one, its an another idea how aproch tar, but in my case it does not work, help ? :(
#! /usr/bin/perl -w
use Net::FTP;
use File::Copy;
my $sfile = "data*.tar"
my $dstftp = "1.1.1.1"
chomp(my @files=`ls $sfile`);
foreach $files (@files) {
copy("$files","work/$files") or die "Copy failed: $!";
my $testit = exec "cd work/ ;tar xf $files ; cd ..";
if ($testit == undef)
{
chomp(my @lpfiles = `ls work/data_10*`);
foreach $lpfiles(@lpfiles) {
$ftp = Net::FTP->new("$dstftp", Debug => 1)
or die "Cannot connect to host: $@\n";
$ftp->login("stt",'stt111')
or die "Cannot login \n ", $ftp->message;
$ftp->binary or die ("cant Binary \n");
$ftp->hash or die ("cant Hash \n");
$ftp->cwd("test/")
or die "Cannot change working directory \n", $ftp->message;
$ftp->put("work/$lpfiles")
or die "put failed \n", $ftp->message;
$ftp->quit;
move("work/$lpfiles","/dev/null");
}
move("$files","/dev/null");
}
else {
print "Nothing to do. No readable TAR files"
}
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to handle broken tars ?
by davido (Cardinal) on May 21, 2004 at 15:55 UTC | |
by SpaceCake (Initiate) on May 21, 2004 at 16:16 UTC | |
|
Re: How to handle broken tars ?
by Stevie-O (Friar) on May 21, 2004 at 15:13 UTC | |
by SpaceCake (Initiate) on May 21, 2004 at 15:41 UTC | |
by Joost (Canon) on May 21, 2004 at 15:46 UTC | |
by SpaceCake (Initiate) on May 21, 2004 at 15:53 UTC | |
|
Re: How to handle broken tars ?
by tbone1 (Monsignor) on May 21, 2004 at 15:47 UTC | |
by SpaceCake (Initiate) on May 21, 2004 at 15:49 UTC |