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"
        }
}

In reply to How to handle broken tars ? by SpaceCake

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.