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



This post if a followup to
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
Password: bash-2.05#

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

if ($conn->expect(20,"Password: "))
print $conn "$password\n";
die "Never got username prompt on bla, ".$conn->exp_error()."\n";


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question