in reply to Re: Uninitalized error for Stdout and Stderr from Net::SSH::Perl
in thread Uninitalized error for Stdout and Stderr from Net::SSH::Perl
Updated code to check $stderr and $exit. $stdout and $stderr have undefined. Do I need to initialize $STDOUT to $stdout
Output from the updated code
#!/usr/bin/env perl -w use strict; use warnings; use Data::Dumper; use Net::SSH::Perl; ###################################################################### +# # LOGIN DETAILS ###################################################################### +# my $server = "10.255.255.10"; my $username = "username"; 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"; print "$stderr\n"; print "$exit\n"; $ssh->cmd("exit");
[root@server-01 New_script]#perl New_script.pl Creating ssh object... done Logging into server... done Running command (df)... done Use of uninitialized value $stdout in concatenation (.) or string at w +lgw2.pl line 29. Use of uninitialized value $stderr in concatenation (.) or string at w +lgw2.pl line 30. 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Uninitalized error for Stdout and Stderr from Net::SSH::Perl
by QM (Parson) on May 12, 2015 at 09:30 UTC |