CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Issue with Net::SCP::Expect

 



tbone587
User

Apr 7, 2012, 8:18 AM

Post #1 of 3 (1070 views)
Issue with Net::SCP::Expect Can't Post

I have recently installed the Net:SCP::Expect module and am trying to have it go through a list of ip address and download a remote file. It works perfectly if there is only 1 ip in my array, but the second there is more I get this error: at /usr/local/share/perl5/Expect.pm line 760ig/Host_Name.conf1: No such file or directory. Do I need to kill the connection or something each time to allow it to go through multiple ips?


Code
use Net::SCP::Expect; 

open HOSTNAMES, "<ew_names.txt" or die;
my @EW_Names = <HOSTNAMES>;
close (HOSTNAMES);

open IPS, "ew_ips.txt" or die;
my @EW_IPs = <IPS>;
close (IPS);


foreach my $ip (@EW_IPs)
{
chomp ($ip);
my $scpe = Net::SCP::Expect->new(user=>'user',password=>'password');
$scpe->auto_yes("1");
foreach my $config (@EW_Names)
{
chomp ($config);

print "Backing up: $config.......\n";
$scpe->scp("$ip:/etc/config/$config","ew_configs/$config");
}
}



tbone587
User

Apr 7, 2012, 9:25 AM

Post #2 of 3 (1067 views)
Re: [tbone587] Issue with Net::SCP::Expect [In reply to] Can't Post

I figured it out. My host name was not changing properly. I changed my code as follows:


Code
se Net::SCP::Expect; 

open HOSTNAMES, "<ew_names.txt" or die;
my @EW_Names = <HOSTNAMES>;
close (HOSTNAMES);

open IPS, "ew_ips.txt" or die;
my @EW_IPs = <IPS>;
close (IPS);

my $index = 0;

foreach my $ip (@EW_IPs)
{
chomp ($ip);
chomp ($EW_Names[$index]);
print "$ip\n";
my $scpe = Net::SCP::Expect->new;
chomp ($config);
$scpe->login("username","mypasswrd");
$scpe->auto_yes("1");

print "Backing up: $EW_Names[$index]...\n";
$scpe->scp("$ip:/etc/config/$EW_Names[$index]","ew_configs/$EW_Names[$index]");

$index++;


}



tbone587
User

Apr 8, 2012, 7:48 AM

Post #3 of 3 (1034 views)
Re: [tbone587] Issue with Net::SCP::Expect [In reply to] Can't Post

I am having one issue. If I am going through a loop of multiple ip addresses to create a scp connection and one is down, the whole script fails. Is there a way to check for successful connection an if it fails just skip to the nxt without the script failing>?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives