Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Save 2 files' diff as 3rd file (working code)

by ybiC (Prior)
on Mar 04, 2002 at 17:25 UTC ( #149161=note: print w/replies, xml ) Need Help??

in reply to Save 2 files' diff as 3rd file

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 data.   ~daaang~

    striving toward Perl Adept
    (it's pronounced "why-bick")
#!/usr/bin/perl -w # $|++; # 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 # # 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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://149161]
[Discipulus]: here at my $work fuc**ing bas**ds proposed to everyone 20 free month of pay to leave
[Discipulus]: I expect a cut of 20% of emplyoment nexet year..
[choroba]: 20 months? :-o
[Discipulus]: up to 20 months.. but you'll be sure to remain unemployed

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2018-05-23 20:56 GMT
Find Nodes?
    Voting Booth?