1823288 Members
3029 Online
109650 Solutions
New Discussion юеВ

Perl SSH::Perl Module

 
SOLVED
Go to solution
David Bellamy
Respected Contributor

Perl SSH::Perl Module

Hello Gurus, I need a little assistance.
I'm trying to develop a GUI monitor application for my operations using Perl/TK. This app will monitor all our HPUX systems. I'm having a little problem with the Net::SSH
module. The problem is that all commands that I issue with this module writes to STDOUT. but i need it to write to a variable so that i can manipulate the data. I have tried redirecting STDOUT in my script to write to a file, which works ok but then i can't change STDOUT back so I can open up the file and manipulate the date. attached is the script I writtened any help will be appreciated.
6 REPLIES 6
Court Campbell
Honored Contributor

Re: Perl SSH::Perl Module

never used the module but according the the perldoc the cmd method returns the stdout, stderr, and exit status. From the synopsis:

use Net::SSH::Perl;
my $ssh = Net::SSH::Perl->new($host);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);

hope that answers your question.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
David Bellamy
Respected Contributor

Re: Perl SSH::Perl Module

Sorry it's the Net::SSH module and it doesn't use the stdout,stderr,exit variables.
Also the Net::SSH::Perl module take to long authenticated.
Court Campbell
Honored Contributor

Re: Perl SSH::Perl Module

i see that now, sorry.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
James R. Ferguson
Acclaimed Contributor

Re: Perl SSH::Perl Module

Hi David:

Perl's 'select' should help you. Consider this:

#!/usr/bin/perl
use strict;
use warnings;
my $log = '/tmp/mylog';
open(FH,">",$log) or die "Can't open '$log': $!\n";
print "This goes to your terminal (STDOUT)...\n";
my $oldfh = select(FH);
print "...but this goes to the log file...\n";
select($oldfh); #...back to STDOUT...
print "...and this you see on your terminal, again\n";
1;

The 'select' returns the currently selected output filehandle, and if another filehandle is supplied, it sets that one as the current output default. Thus, a write or a print without a filehandle argument defaults to this filehandle.

Regards!


...JRF...
Ralph Grothe
Honored Contributor
Solution

Re: Perl SSH::Perl Module

Hi David,

I have to admid to never have used Net::SSH
as I consider it somewhat redundant because it is more or less only a wrapper around the ssh command.
But it has a more palatable interface than doing the forking and piping with standard Perl IPC techniques.
So I just have looked up the POD of Net::SSH
http://search.cpan.org/~ivan/Net-SSH-0.08/SSH.pm
only to discover that it already comes with a
sshopen2() function for pretty straight forward access to STDIN and STDOUT.
Please, see the example in the POD.
If you are also interested in STDERR use sshopen3(), which gives you even handles to three pipes.
Madness, thy name is system administration
David Bellamy
Respected Contributor

Re: Perl SSH::Perl Module

Thanks to all. Ralph thanks the answer was in front of me all the time and i wasn't seeing it.