#!/usr/bin/perl -w use strict; use Expect; my $exp = Expect->spawn("telnet remoteunisyssystem") or die "Cannot spawn telnet: $!\n";; $exp->log_file("testlog"); my $spawn_ok; my $timeout = 15; $exp->expect($timeout, [ qr'Do you want to send a file? Y/\[N\]: $', sub { my $fh = shift; print $fh "Y\n"; exp_continue; } ], [ 'Enter an upload command to your modem program now.', sub { my $fh = shift; print $fh "send somefilename\n"; exp_continue; } ], [ eof => sub { if ($spawn_ok) { die "ERROR: premature EOF in login.\n"; } else { die "ERROR: could not spawn telnet.\n"; } } ], [ timeout => sub { die "No login.\n"; } ], '-re', qr'[#>:] $', #' wait for shell prompt, then exit expect );