Hi there,
It's been a while since I've coded in perl/expect.
I am finding that when sending the "request snmp spoof-trap $trap" in
the for loop that the command is sent without waiting for the prompt.
In fact they are sent as fast as they can be.
I am trying to figure out why that is happening. since expect is not
waiting for the prompt the commands get truncated and CLI errors result,
etc.
What am I doing wrong?
Cheers,
Noah
--- snip ---
#!/usr/bin/perl
#
use Expect;
#use Expect::Simple;
#
#--- ENSURE TO HAVE SUFFICIENT COMMAND LINE ARGUMENTS !
----------------------#
#
if ( $#ARGV != 2 ) {
printf("USAGE: $0 <host> <user> <pw>\n");
exit(-1);
}
$host = shift;
$user = shift;
$pw = shift;
#
#--- CONFIGURATION
-----------------------------------------------------------#
#
$cmd = "ssh -l $user $host";
$prompt = "[Pp]assword";
$data_file = "traps.txt";
open (DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close (DAT);
#
#--- START SSH LOGIN SEQUENCE !
----------------------------------------------#
#
$exp = new Expect();
$exp->raw_pty(0);
$exp->spawn($cmd);
#
#--- LOGIN AND INTERACT !
----------------------------------------------------#
#
$exp->expect(10000, [ $prompt => sub { $_[0]->send("$pw\n"); } ]);
$prompt = "$user\@$host>";
$exp->expect(10000, [ $prompt => sub { $_[0]->send("set cli
screen-length 0\n"); } ]);
$x = 2;
foreach $trap (@raw_data) {
$prompt = "$user\@$host>";
$exp->expect(10000, [ $prompt => sub { $_[0]->send("request snmp
spoof-trap $trap\n"); } ]);
$x++;
}
$exp->interact();
print "\n\n";
$exp->soft_close();
|