#!/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 #### #!/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 $host: ". $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->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 unlink $tmpdir.$host3.$evalfile; unlink $tmpdir.$host4.$evalfile;