<?xml version="1.0" encoding="windows-1252"?>
<node id="1001275" title="Unable to store the command output from Net::SSH2. Please help." created="2012-10-28 12:30:28" updated="2012-10-28 12:30:28">
<type id="115">
perlquestion</type>
<author id="941553">
perl514</author>
<data>
<field name="doctext">
&lt;P&gt;Venerable Monks,&lt;/P&gt;

&lt;P&gt;I am trying to collect the ouptut of a command that is run after logging in to a NAS Array through SSH.&lt;/p&gt;

&lt;P&gt;The command, &lt;code&gt; nas_server -list &lt;/code&gt; gives the statuts of the NAS Array. I am trying the following script to do it. For some reason, its not capturing the actual command output of the command in the &lt;code&gt; @output &lt;/code&gt; array even after stating &lt;code&gt; my @output = $chan-&gt;exec('nas_server -list');&lt;/code&gt; It seems to capture the value 1, which I presume corresponds with the successful status of the command being executed.&lt;/P&gt;

&lt;p&gt; Here is the complete script&lt;/p&gt;

&lt;code&gt;
#!/usr/bin/perl;
use Modern::Perl;
use 5.014;
use Net::SSH2;

my $nasip = '127.0.0.1'; #Actul IP is different. 

my $user = 'user';

my $pass = 'passwd';

my $ssh = Net::SSH2-&gt;new();

$ssh-&gt;debug(1);

say "Connecting to $nasip";

$ssh-&gt;connect("$nasip") || warn "$!";

$ssh-&gt;auth_password("$user","$pass");

my $chan = $ssh-&gt;channel();

my @output = $chan-&gt;exec('nas_server -list');

say "output is: @output";

$chan-&gt;close();

&lt;/code&gt;

&lt;p&gt; And here is the output. The IP given in the example is 127.0.0.1, but I am actually using a different IP to login to the NAS Array&lt;/p&gt;

&lt;code&gt;
Connecting to 127.0.0.1
libssh2_channel_open_ex(ss-&gt;session, pv_channel_type, len_channel_type, window_size, packet_size, ((void *)0) , 0 ) -&gt; 0x11353dc
output is: 1
Net::SSH2::Channel::DESTROY
Net::SSH2::DESTROY object 0x9b745c
&lt;/code&gt;


&lt;P&gt;Firstly, I know very rudimentary Perl and I am back here after almost a year, so if any mistakes in the script above please do forgive me. Thanks a lot to [vdubjunkie], because If not for his node [id://979541], I wouldn't even have written the above script.&lt;/P&gt;

&lt;p&gt; The NAS Array (Network Attached Storage Array) is an EMC Storage Array - NS960. I am running the script from a Windows 2003 host on which Perl Version 5.14.2 is installed.&lt;/p&gt;

 &lt;P&gt;Kindly request you please guide me to a site where a detailed tutorial for the Net:SSH2 Module is given. I did go through the perldoc, also googled, but didn't find anything that I could understand. :(
&lt;/P&gt;




&lt;div class="pmsig"&gt;&lt;div class="pmsig-941553"&gt;
&lt;P&gt;Perlpetually Indebted To PerlMonks&lt;/P&gt;

&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
