#!/usr/local/bin/expect -f #!expect -f $1 $2 set hostid [lrange $argv 1 1] set retfil [lrange $argv 2 2] spawn kermit sleep .4 send -s -- "set protocol zmodem {rz -E} {rz -E} {sz --zmodem --delay-startup 10 -e -w 2048 %s} {sz -a %s} {rz -E} {rz -E}\r" send -s -- "telnet $hostid\r" -exact " Do you want to send a file? Y/\[N\]: " { sleep .2 send -s -- "y\r" expect -exact " Enter an upload command to your modem program now." sleep 5 send -s -- "\034\003" send -s -- "send $retfil\r" send -s -- "c\r" } #### #!/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 );