A round of thank you's and upvotes to all the Really Fine Monks who responded to my question. 8^)
mattr hit the nail on the head, when he said "erase every appearance in @all of each element in @err", as did Zaxo with "relies on error log to contain everything to be rejected... dependency on both logs having error messages in same order."
Code below works fine on Cygwin and Debian with included sample data, but blows it on real rsync.pl data. ~daaang~
cheers,
Don
striving toward Perl Adept
(it's pronounced "why-bick")
#!/usr/bin/perl -w
# rtest9.pl
$|++; # stdout hot
use strict; # avoid d'oh! bugs
require 5; # for following modules
use Cwd 'chdir'; # move to particular directory
use Tie::IxHash; # insertion-order retrieval for hash
# my $logDir = '/cygdrive/C/Rsync/logs';
my $logDir = '/home/joe/rtest';
my $allLog = "all.log";
my $errLog = "err.log";
my $dirLog = "dir.log";
my $fileLog = "file.log";
chdir "$logDir";
open ALL, "< $allLog" or die $!;
my @all = <ALL>;
close ALL or die $!;
open ERR, "< $errLog" or die $!;
my @err = <ERR>;
close ERR or die $!;
tie my %allCount, "Tie::IxHash";
$allCount{$_}++ for( @all, @err );
my (@dirfile, @errchk);
for( keys %allCount ) {
if ( $allCount{$_} == 1 ) { push @dirfile, $_; }
else { push @errchk, $_; }
}
my (@dir, @file);
for(@dirfile){
if ( $_ =~ /\// ) {
push @dir, $_;
} else {
push @file, $_;
}
}
open DIR, "> $dirLog" or die $!;
print DIR "$_" for(@dir);
close DIR or die $!;
open FIL, "> $fileLog" or die $!;
print FIL "$_" for(@file);
close FIL or die $!;
=pod
== all.log ==
file1
file2
error1
error2
file3
dir1/
dir2/
== err.log ==
error1
error2
=cut
And here's my latest efforts. Now using File::Rsync. Not completely out of the woods, but making progress...
#!/usr/bin/perl -w
# rsf.pl
# pod at tail
$|++; # stdout hot
use strict; # avoid d'oh! bugs
require 5; # for following modules
use File::Rsync; # wrapper for rsync directory sync tool
my $logDir = '/home/joe/rtest';
my $outLog = "$logDir/out.log";
my $errLog = "$logDir/err.log";
## RECEIVE
my $srchost = 'indy:';
# my @src = qw(perls debs);
my $src = 'perls';
my $dest = '/home/joe/rtest/';
## SEND
# my $srchost = '';
# my @src = qw(/home/joe/rtest /usr/local/perls);
# my $dest = 'indy::Test';
my $obj = File::Rsync->new({
srchost => $srchost,
src => \@src,
dest => $dest,
});
# src => $src,
$obj->defopts({
archive => 1,
verbose => 1,
recursive => 1,
owner => 1,
perms => 1,
group => 1,
times => 1,
debug => 0,
compress => 0,
'dry-run' => 0,
});
$obj->exec or warn "Rsync notice - check logs\n";
open OUT, "> $outLog" or die $!;
open ERR, "> $errLog" or die $!;
my @out = $obj->out;
print OUT for(@out);
my @err = $obj->err;
my $stat = $obj->status;
my $rstat = $obj->realstatus;
print ERR for(@err);
print OUT "status = $stat\n";
print OUT "realstatus = $rstat\n";
close OUT or die $!;
close ERR or die $!;
=head1 UPDATE
2002-03-11 16:45 CST
Variableized object options
Test on Cygwin
rsh=>'/usr/bin/ssh' errs, ignored
Debug sending to rsync server
user@rhost::module only with rsh=>'/usr/local/bin/ssh'
"@list=$obj->list" is only for no "dest"
2002-03-09 22:15 CST
Initial working code
=head1 TODO
Figure out File::Rsync syntax to receive from multiple rsync modules
@ERROR: Unknown module 'mod1 mod2'
There is also a method for passing multiple source paths to a
remote system by passing the remote hostname to the srchost key
and passing an array ref to the source key... single trailing
colon on the name...
Loopify somehow for send+receive
Re-test on Cygwin
Pod::Usage
Getopt::Long
? Logfile::Rotate ?
? Parallel::ForkManager ?
=cut
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.