perl_Net::SCP::Expect实现批量分发文件
今天要在大量机器同一目录分发同一个文件,下面是脚本:已经打通ssh通道(不打通也可以,因为我是使用指定用户执行的,不然老提示yes/no)
#!/usr/bin/perl
use strict;
use Getopt::Std;
use Net::SCP::Expect;
use vars qw($opt_f $opt_l $opt_t $opt_h);
getopts('f:l:t:h');
get_args();
my ($filename,$catalog,$type,$help);
open (HD,"$type") || die "Cannot find file:$!\n";
my @jd=;
close (HD);
my $jd;
foreach $jd(@jd) {
chomp ($jd);
#get_args();
my$scpe = Net::SCP::Expect->new(host=>$filename,user=>"usr",password=>'user_password',auto_yes=>1,timeout=>20);
$scpe->scp("$filename","$jd:$catalog");
sub get_args{
$filename = $opt_f if $opt_f;
$catalog = $opt_l if $opt_l;
$type = $opt_t if $opt_t;
&Usage() if (!defined($filename) || !defined($catalog));
}
sub Usage {
页:
[1]