title: How to run SSH commands using Net::SSH::Perl?
body: <p>I don't know if I managed to install <a href="https://metacpan.org/module/Net%3a%3aSSH%3a%3aPerl" rel="nofollow"><code>Net::SSH::Perl</code></a> module successfully but I can't seem to be able to run the following code:</p>
  
  <pre><code>my $ssh = Net::SSH::Perl-&gt;new($remote_host);
  $ssh-&gt;login($username, $password);
  print "login done", "\n";
  my ($out, $err, $exit) = $ssh-&gt;cmd($cmd);
  print "$out", "\n";
  </code></pre>
  
  <p>I am able to login but cannot print the <code>$out</code>. I keep getting this error:</p>
  
  <pre><code>Use of uninitialized value $out in string at test_ssh.pl line 28.
  </code></pre>
  
  <p>Line 28 refers to <code>print "$out", "\n";</code>.</p>
  
  <p>I am running this code on Cygwin. What should I do now?</p>
  
  <p>EDIT:
  I got the following error msg when I ran <code>my $ssh = Net::SSH::Perl-&gt;new($remote_host, options =&gt; ["Debug yes"]);</code>:</p>
  
  <pre><code>Use of uninitialized value $out in string at test_ssh.pl line 29 (#1)
      (W uninitialized) An undefined value was used as if it were already
      defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
      To suppress this warning assign a defined value to your variables.
  
      To help you figure out what was undefined, perl will try to tell you the
      name of the variable (if any) that was undefined. In some cases it cannot
      do this, so it also tells you what operation you used the undefined value
      in.  Note, however, that perl optimizes your program and the operation
      displayed in the warning may not necessarily appear literally in your
      program.  For example, "that $foo" is usually optimized into "that "
      . $foo, and the warning will refer to the concatenation (.) operator,
      even though there is no . in your program.
  </code></pre>
  
  <p>EDIT2:
  Here's my full code</p>
  
  <pre><code>use strict;
  use warnings;
  use Net::SSH::Perl;
  
  my $remote_host = '&lt;host ip address&gt;';
  my $password    = 'pass';
  my $username    = 'user';
  my $cmd         = 'copy run tftp:&lt;my own ip address&gt;';
  
  warn "Starting SSH Services:...";
  my $ssh = Net::SSH::Perl-&gt;new($remote_host, debug =&gt; 1);
  print "done", "\n";
  
  warn "Starting Login:...";
  $ssh-&gt;login($username, $password);
  print "login done", "\n";
  
  warn "Starting command:...";
  #$ssh-&gt;cmd($cmd);
  #my($stdout, $stderr, $exit) = $ssh-&gt;cmd($cmd);
  my ($out, $err, $exit) = $ssh-&gt;cmd($cmd);
  print "$out", "\n";
  </code></pre>
  
  <p>The error message on "print "$out","\n";" line:</p>
  
  <pre><code>&lt;Computername&gt;: channel 1: new [client-session]
  &lt;Computername&gt;: Requesting channel_open for channel 1.
  &lt;Computername&gt;: Entering interactive session.
  &lt;Computername&gt;: Channel open failure: 1: reason 4:
  Use of uninitialized value $out in string at test_ssh.pl line 29.
  </code></pre>
  
  <p>LAST EDIT: I decided to use Net::Appliance::Session to login via SSH to the network devices instead. it's a lot easier to use than Net::SSH::Perl.</p>