Using SSH and Expect to return STDOUT output from a C executable

Discussion in 'Perl Misc' started by jrpfinch, May 9, 2007.

  1. jrpfinch

    jrpfinch Guest

    This post if a followup to
    http://groups.google.co.uk/group/pe...?lnk=gst&q=piping out&rnum=1#1ed10e63c905a3e7.
    It is a distinct topic, however, so I've started a new thread.

    In the previous post, I managed to create a script that permanently
    logged the output from a C executable that was always open. It used
    the Expect module.

    I would now like to do the same thing but remotely over SSH. For
    security reasons, I am not allowed to go for the easy option of
    exchanging unpassworded keys and using batch mode.

    The script at the base of this email simply returns the following
    output, without returning the output from 'ls':

    bash-2.05# perl expectssh.pl
    Password: bash-2.05#

    use strict;
    use warnings;
    use Expect;
    my $password = "password";
    my $conn = Expect->spawn("ssh root\@10.247.16.2 ls") or die "Couldn't
    spawn ssh\n";

    if ($conn->expect(20,"Password: "))
    {
    print $conn "$password\n";
    }
    else
    {
    die "Never got username prompt on bla, ".$conn->exp_error()."\n";
    }
     
    jrpfinch, May 9, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Strandgaard

    how to expect eof with expect+pty

    Simon Strandgaard, Dec 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    366
    Simon Strandgaard
    Dec 20, 2006
  2. Manish Sapariya

    Net::SSH expect like interface

    Manish Sapariya, Apr 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    317
    Brian Candler
    Sep 25, 2007
  3. Replies:
    6
    Views:
    307
    Martin Kissner
    Feb 10, 2005
  4. Phil
    Replies:
    0
    Views:
    171
  5. Deepika
    Replies:
    2
    Views:
    221
    Deepika
    Nov 14, 2006
Loading...

Share This Page