I am using Net::SSH::Perl to ssh and run command. I can not get print stdout or stderr. Uninitialized error is reported. Looks like module is initializing and somewhere it's not reporting. Any thoughts will will helpful.

script output START

Creating ssh object... done Logging into server... done Running command (df)... done Use of uninitialized value $stdout in concatenation (.) or string at p +erlscript.pl line 28.

script output END

script START

#!/usr/bin/env perl -w use strict; use warnings; use Net::SSH::Perl; ###################################################################### +# # LOGIN DETAILS ###################################################################### +# my $server = "10.255.255.10"; my $username = "user"; my $password = "password"; # Log into server print "Creating ssh object... "; my $ssh = Net::SSH::Perl->new($server); # Error check this print "done\n"; print "Logging into server... "; $ssh->login($username, $password); # Error check this print "done\n"; # Check df my $command = "df"; print "Running command ($command)... "; my ($stdout, $stderr, $exit) = $ssh->cmd($command); # Check output print "done\n"; print "$stdout\n"; $ssh->cmd("exit");

script END

Debug output START

Use of uninitialized value $stdout in concatenation (.) or string at p +erlscript.pl line 28. server-01: channel 2: new [client-session] server-01: Requesting channel_open for channel 2. server-01: Entering interactive session. server-01: Requesting service exec on channel 2. server-01: channel 2: open confirm rwindow 0 rmax 32768 server-01: input_channel_request: rtype exit-status reply 0 server-01: input_channel_request: rtype eow@openssh.com reply 0 server-01: channel 2: rcvd eof server-01: channel 2: output open -> drain server-01: channel 2: rcvd close server-01: channel 2: input open -> closed server-01: channel 2: close_read server-01: channel 2: obuf empty server-01: channel 2: output drain -> closed server-01: channel 2: close_write server-01: channel 2: send close server-01: channel 2: full closed [root@server-01 Name]#

Debug output END


In reply to Uninitalized error for Stdout and Stderr from Net::SSH::Perl by waytoperl

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.