In this line:
my(@hostline, $stderr, $exit) = $cs->cmd('sh run | inc hostname');
gives you all return values in @hostline and nothing in $stderr or $exit. If you are getting logged in, it should be able to run commands. Using print is a very valuable diagnostic tool. I would probably even go as far as making something very simple for testing.
use strict;
use warnings;
use Net::SSH::Perl;
$ENV{'HOME'} = 'c:\strawberry';
my $ip = 'xxx';
my $user = '********';
my $pw = '********'; # If you use single quotes, only single quotes
+will to be escaped with '\'
my $cs = Net::SSH::Perl->new($ip);
if ($cs->login( $user, $pw)) {
print $cs->cmd('sh run | inc hostname');
}
else {
warn "Unable to login\n";
}
$cs->close;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|