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

I can't figure out what's wrong with this script for the life of me. It runs fine until
print $remote "$command\r"
which does absolutely nothing.

On a related note, does anyone know of a way to construct a script that would automate the chain of rlogins and telnets and then allow the user to take control.

#!/usr/local/bin/perl use Expect; if ($#ARGV != 1) { die "Usage: rexec remote_host command\n"; } $remote_host = $ARGV[0]; $command = $ARGV[1]; $gateway = "abc123"; $remote = Expect->spawn("rlogin $gateway"); $remote->expect(5, "$gateway%") || die "No shell prompt on $gateway\n" +; $sss = "def456"; print $remote "telnet $sss\r"; $remote->expect(5, "login: ") || die "No login prompt on $sss\n"; print $remote "foo\r"; $remote->expect(5, "word:") || die "No password prompt on $sss\n"; print $remote "bar\r"; $remote->expect(5, "\$ ") || die "No shell prompt on $sss\n"; print $remote "rlogin $remote_host\r"; $remote->expect(20, "\$") || die "No shell prompt on $remote_host\n"; print $remote "$command\r"; $remote->hard_close();

Edit Masem - Code tags

Replies are listed 'Best First'.
Re: Problem with Expect
by blakem (Monsignor) on Nov 08, 2001 at 23:43 UTC
Re: Problem with Expect
by clemburg (Curate) on Nov 09, 2001 at 14:34 UTC

    Hm, I don't know about a Perl way of doing this (simply never had a need to do this in Perl), but the real Expect tool has the "interact" command for doing this.

    See "Exploring Expect" (ISBN 1565920902) by Don Libes, page 8, section "Partial Automation".

    Hm, seems like the Expect Perl module has also an "interact()" method ...

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com