Hi all,
i'm searching for a solution / or any ideas to get a better working to the epochal mtime of remote files to compare them and after comparing copy only the youngest file to local-dir. Any ideas?

I've tried like this ... but it doesn't work:

#!/usr/bin/perl -w use strict; use warnings; use lib "/opt/perl_addmodules/lib/site_perl"; use Net::OpenSSH; use Data::Dumper; ######################################################## my (%ssh, $evalh3, $evalh4, $acthost,$ssha); ######################################################## my $host4 = 'foo'; my $host3 = 'bar'; my @hosts = ($host3,$host4); my @files = ('file1.csv','file2.csv','file3.csv'); my $realrun = 'n'; my $user = 'root'; my $localdir = '/.../'; my $localbakdir = '/.../.../'; my $remotedir = '/.../'; my $reffile = $remotedir.$files[0]; my $tmpdir = '/tmp/'; my $evalfile = '_eval'; # ####################### main ###################### if ($realrun eq 'n') { print "Main: Simulate-Run: .................... \n"; } # Make Multiple-Master-ssh Connections for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($user.'@'.$host, async =>1); $ssh{$host}->error and warn "Couldn't establish SSH connection $ho +st: ". $ssh{$host}->error; print " --------------$host-------------- \n"; if ($host eq $host3){ $evalh3 = $ssh{$host}->capture((stat("$reffile"))[9]); } # This does +n't work !! if ($host eq $host4){ $evalh4 = $ssh{$host}->capture((stat("$reffile"))[9]); } # This does +n't work !! } # end for if ($evalh3 > $evalh4) { $acthost = $host3; } else { $acthost = $host4; } $ssha = Net::OpenSSH->new($user.'@'.$acthost); $ssha->error and warn "Couldn't establish SSH connection: ". $ssha->er +ror; foreach (@files) { if (-e $localdir.$_) { print "Main: File: $_ exist and will be moved to $localbakdir +\n"; if ($realrun eq 'y') { move($localdir.$_, $localbakdir.$_); $ssha->scp_get({quiet=>0, copy_attrs=>1}, $remotedir.$_, $ +localdir.$_); } else { print "Main: Simulate-Run: $_ to copy from $acthost... +................. \n"; } } else { print "Main: File: $_ does not exist \n"; } } #end foreach

.... This was what i want ... but...maybe... someone has an idea to get it work - perhaps with expect?

...And for completeness: here is my workaround ...but i hope there is a better way...:

#!/usr/bin/perl -w use strict; use warnings; use lib "/opt/perl_addmodules/lib/site_perl"; use Net::OpenSSH; use File::Copy; use File::Basename; use Data::Dumper; use POSIX qw(setuid); ######################################################## my (%ssh, $evalh3, $evalh4, $acthost,$ssha); ######################################################## my $host4 = 'foo'; my $host3 = 'bar'; my @hosts = ($host3,$host4); my @files = ('file1.csv','file2.csv','file13.csv'); my $realrun = 'n'; my $user = 'root'; my $localdir = '/usr/.../...../'; my $localbakdir = '/usr/.../........./'; my $remotedir = '/usr/.../......./'; my $reffile = $remotedir.$files[0]; my $tmpdir = '/tmp/'; my $evalfile = '_eval'; # ####################### main ###################### if ($realrun eq 'n') { print "Main: Simulate-Run: .................... \n"; } # Make Multiple-Master-ssh Connections for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($user.'@'.$host, async =>1); $ssh{$host}->error and warn "Couldn't establish SSH connection $ho +st: ". $ssh{$host}->error; print " --------------$host-------------- \n"; $ssh{$host}->scp_get({quiet=>0, copy_attrs=>1 }, $reffile, $tmpdir +.$host.$evalfile); } # end for if (-e $tmpdir.$host3.$evalfile) { $evalh3 = (stat("$tmpdir$host3$evalfile"))[9]; } else { $evalh3 = 0; } if (-e $tmpdir.$host4.$evalfile) { $evalh4 = (stat("$tmpdir$host4$evalfile"))[9]; } else { $evalh4 = 0; } print "$host3: ... FileAge: ... $evalh3 \n"; print "$host4: ... FileAge: ... $evalh4 \n"; if ($evalh3 > $evalh4) { $acthost = $host3; } else { $acthost = $host4; } print " --------------$acthost-------------- \n"; $ssha = Net::OpenSSH->new($user.'@'.$acthost); $ssha->error and warn "Couldn't establish SSH connection: ". $ssha->er +ror; foreach (@files) { if (-e $localdir.$_) { print "Main: File: $_ exist and will be moved to $localbakdir +\n"; if ($realrun eq 'y') { move($localdir.$_, $localbakdir.$_); $ssha->scp_get({quiet=>0, copy_attrs=>1}, $remotedir.$_, $ +localdir.$_); } else { print "Main: Simulate-Run: $_ to copy from $acthost... +................. \n"; } } else { print "Main: File: $_ does not exist \n"; } } #end foreach unlink $tmpdir.$host3.$evalfile; unlink $tmpdir.$host4.$evalfile;

Thanks and regards Armin

In reply to OpenSSH capture perl-command by Alasharin

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.