I am trying to SCP from one machine to multiple machines. I have an identity file to use for performing passwordless authentication. I came across Net::SCP::Expect module and it does the job well for one machine but when it moves on to copying the component to another machine, it fails. Here's the code:
use strict; use warnings; use Cwd; use File::Copy; use Getopt::Long; use Net::SSH::Perl; use Net::SCP::Expect; my ($war_name, $wrapper_name, $host, $user, $war_build_path, $war_full +_path, $war_archive_path, $war_archive_host, $HOME, $scpe, @id_file); usage() if ( @ARGV < 6 or !GetOptions( 'war_name:s' => \$war_name, 'war_path:s' => \$war_build_path, 'wrapper_name:s' => \$wrapper_name, 'host=s' => \$host, 'user=s' => \$user, ) ); if ($war_name && $war_build_path && $host && $user) { printf "Initiating subroutine to copy war on remote machine...\n"; &copy_war; } sub copy_war { $war_full_path = "/home/tom/slave/workspace/Rel_Build/rec_dist/$wa +r_name"; $war_archive_path = "/home/tom"; $war_archive_host = "xx.xxx.xxx.xx"; if ( -f $war_full_path ) { printf "Copying war: $war_name\n"; printf "Target Machine: $host\n"; printf "User: $user\n\n"; $scpe = Net::SCP::Expect->new( identity_file => "/home/tom/.ssh/i +d_file", host => $host, user => $user, ); $scpe->scp("$war_full_path", "$HOME") or die $scpe->{errstr}; printf "War copied on deployment machine. Now moving on to nex +t task of archiving the war...\n"; $scpe = Net::SCP::Expect->new( identity_file => "/home/tom/.ssh/i +d_file", host => $war_archive_host, user => $user, ); $scpe->scp("$war_full_path", "$war_archive_path") or die $scpe +->{errstr}; printf "War archived on master\n"; } else { printf "War not found\n"; } }

Output:

Initiating subroutine to copy war on remote machine... Copying war: remote-web.war Target Machine: xx.xxx.xxx.xx User: tom Use of uninitialized value $HOME in string at /home/tom/deploy.pl line + 59. War copied on deployment machine. Now moving on to next task of archiv +ing the war... at /home/tom/perl/5.18.2/lib/site_perl/5.18.2/Expect.pm line 760. I tried reading Expect.pm file around the error # but couldn't underst +and. Does it has anything to do with the earlier object not getting f +reed up? I couldn't find any method on the CPAN page for this module +to close the connection.

In reply to Unable to do SCP on multiple machines using Perl's Net::SCP::Expect module by Technext

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.