natxo has asked for the wisdom of the Perl Monks concerning the following question:

hi, I would like to get some output from an UPS (http://en.wikipedia.org/wiki/Uninterruptible_power_supply) unit. This thing has a ssh and a web interface. If I login interactively to the unit, this is what I see:
slogin user@ups Authenticated with partial success. user@ups's password: American Power Conversion Network Management Card AOS + v3.7.3 (c) Copyright 2009 All Rights Reserved Smart-UPS & Matrix-UPS APP + v3.7.2 ---------------------------------------------------------------------- +--------- Name : asset Date : 29.08.201 +3 Contact : sysadmin Time : 12:27:03 Location : somewhere User : Administr +ator Up Time : 0 Days 4 Hours 9 Minutes Stat : P+ N+ A+ Smart-UPS 1500 RM named asset : On Line, No Alarms Present ------- Control Console ---------------------------------------------- +--------- 1- Device Manager 2- Network 3- System 4- Logout <ESC>- Main Menu, <ENTER>- Refresh, <CTRL-L>- Event Log
So this is like a motd when you login. How can I capture this info? I have tried this:
use strict; use warnings; use Net::OpenSSH; my $host = shift; my $stdin; my $stdout; my $stderr; print $host, "\n"; my $ssh = Net::OpenSSH->new( $host, user => "user", password => "password", timeout => 30, default_stdin_fh => $stdin, default_stdout_fh => $stdout, default_stderr_fh => $stderr, ); $ssh->error and die "Can't ssh to $host: " . $ssh->error; print "stdin is $stdin\n" if defined $stdin ; print "stdout is $stdout\n" if defined $stdout; print "stderr is $stderr\n" if defined $stderr ;
But I am afraid I am getting nothing. I know I can log in, I see that on the log file, but am a bit confused about getting the info. Any help appreciated.

Replies are listed 'Best First'.
Re: Net::OpenSSH to ups appliance
by salva (Canon) on Aug 29, 2013 at 12:18 UTC
    The SSH implementation on that device seems crippled. It doesn't perform authentication using the SSH protocol. Instead it asks for the password when a shell is started on some SSH channel.

    Net::OpenSSH will not handle authenticating against such systems. Though, if all you want is getting the motd, the following code may work:

    my $ssh = Net::OpenSSH->new($host, user => $user, timeout => 30); my $motd = $ssh->capture({stdin_data => "$password\n\n4\n", stderr_to_stdout => 1}); print $motd;

    Alternatively, just use Expect.

      Thanks for the tip. This is what is working for me now:
      my $ssh = Net::OpenSSH->new( $host, user => "user", password => "password", timeout => 30, ); my $motd = $ssh->capture( { stderr_to_stdout => 1, } ); print $motd;
      The devices are indeed crippled, and unfortunately we need to resort to this kind of stuff to know when they break.