in reply to Problems with Net::OpenSSH

As Anonymous Monk has already told you, the login phase is managed by the module and what you get from open2pty is not the login prompt but a shell on the remote device.

Anyway, usually, the following hack works:

my $ssh = Net::OpenSSH->new("$username:$password\@$ip", timeout => 30) +; $ssh->error and die "unable to connect to remote host: ". $ssh->error; my $out = $ssh->capture({stdin_data => "show ip arp\n"});
It just starts a remote shell, pipes the command through its stdin and captures the output.

If that doesn't work, you will have to revert to Expect. Running the following one-liner from the command line will allow you to interact with the remote shell as returned by open2pty so you can experiment with it and see what you should expect.

perl -MNet::OpenSSH -e 'Net::OpenSSH->new(q(USER:PASSWD@HOST))->system +({tty=>1})'

Replies are listed 'Best First'.
Re^2: Problems with Net::OpenSSH
by aeaton1843 (Acolyte) on Nov 23, 2010 at 16:05 UTC

    The hack works except that it doesn't return without issuing control-c. Is there some way around that? Part of the output follows.

    andy@andy-desktop:~/core/arpinfo$ ./test3.pl ^C NetServ_Lab_SW_2#show ip arp Protocol Address Age (min) Hardware Addr Type Interface Internet 4.2.4.1 - 0016.c859.1b41 ARPA Vlan42 Internet 192.168.120.1 - 0016.c859.1b42 ARPA Vlan499 ... ... NetServ_Lab_SW_2# NetServ_Lab_SW_2#andy@andy-desktop:~/core/arpinfo$
      Is there any command you can send the remote box to close the session?

      For instance:

      my $out = $ssh->capture({stdin_data => "show ip arp\nexit\n"});