Friday I had some troubles about how to detect tar files in use, which are uploaded to the box with FTP. I had lots of input from monks here, al'do I did not realize any of they suggestions, they did give me an idea how to solve my problem. TAR does not give any output if extraction is successful, at least none that I know. So I thought about putting that in the variable and use that one. Unfortunately it does not work so good. Can you, perlmonks, take a look and enlighten my path ?
#! /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("user",'passwd')
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"
}
}