#!/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 $host: ". $ssh{$host}->error; print " --------------$host-------------- \n"; if ($host eq $host3){ $evalh3 = $ssh{$host}->capture((stat("$reffile"))[9]); } # This doesn't work !! if ($host eq $host4){ $evalh4 = $ssh{$host}->capture((stat("$reffile"))[9]); } # This doesn'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->error; 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