in reply to Retrieving status data from a device with SSH 2 using Perl

You are probably suffering a variation of the problem described in Re: Unable to run command on Cisco switch. In this case, you get different output when you run commands in interactive mode (through the shell) than when you run them directly from the SSH command line (or through a Perl module, it's the same).

If you really need those codes use Expect (alone, wrapped by Net::SSH::Expect or combined with Net::OpenSSH) to interact with a shell on the remote device.

  • Comment on Re: Retrieving status data from a device with SSH 2 using Perl

Replies are listed 'Best First'.
Re^2: Retrieving status data from a device with SSH 2 using Perl
by nmorenod (Novice) on Feb 17, 2010 at 10:47 UTC

    Yes... probably there are different modes. Is there a way to make the server give the answers to the commands as if they were written using the shell?

    For this solution you suggest with Expect, should I use it directly with the shell executing ssh from the Perl script? Because I guess that if I use Expect with the Net::OpenSSH commands, I have to work with the same incomplete answer as if I were using the commands directly.

    Thanks again!

    PS: Salva? Betanzos? Super López? I guess I'm not the only Spaniard here!

      Because I guess that if I use Expect with the Net::OpenSSH commands, I have to work with the same incomplete answer as if I were using the commands directly.

      You can use Net::OpenSSH to establish the connection to the remote machine and then run an interactive shell managed with Expect as follows:

      my ($pty, $pid) = $ssh->open2pty() # and empty command line invokes a +shell! or die "unable to run remote shell"; my $expect = Expect->init($pty); $expect-> ...
      Though, if that is all you need to do in the remote server, using Expect alone will be almost the same, the only difference is that you will have to take care of authentication also.
      PS: Salva? Betanzos? Super López? I guess I'm not the only Spaniard here!

      No, you are not, where are you from?

        Ok, then both are valid for me :) Now it's time to deal with Expect, but my first approaches look good.

        No, you are not, where are you from?

        Que sí, medio madrileño medio toledano, pa'servirle...

        Thanks again