perl模块Net::SCP::Expect批量下发文件
#!/usr/bin/perluse Getopt::Std;
use Net::SCP::Expect;
use strict;
use vars qw($opt_s $opt_u $opt_H $opt_d $opt_p $opt_h);
getopts('s:u:H:d:p:h');
my ($src_file,$username,$Hostname,$dest_file,$passwd,$help,$jd);
&main();
sub main {
get_args();
scp_auto();
}
sub get_args {
$src_file = $opt_s if $opt_s;
$username = $opt_u if $opt_u;
$Hostname = $opt_H if $opt_H;
$dest_file = $opt_d if $opt_d;
$passwd = $opt_p if $opt_p;
$help = $opt_h if $opt_h;
&Usage() if (!defined($src_file) || !defined($username) || !defined($Hostname)
|| !defined($dest_file) || !defined($passwd));
}
sub scp_auto {
if (-f $Hostname) {
open (HD,"$Hostname") || die "Cannot find file :$!\n";
my @jd=;
close (HD);
foreach $jd(@jd) {
chomp ($jd);
my$scpe = Net::SCP::Expect->new(host=>$jd,user=>"$username",password=>"$passwd",
auto_yes=>1,timeout=>200,verbose=>1,recursive=>1);
print "$jd ---------------------\n";
$scpe->scp("$src_file","$dest_file");
}
} else {
my$scpe = Net::SCP::Expect->new(host=>$Hostname,user=>"$username",password=>"$passwd"
,auto_yes=>1,timeout=>200,verbose=>1,recursive=>1);
print "$Hostname ---------------------\n";
$scpe->scp("$src_file","$dest_file");
}
}
sub Usage{
页:
[1]