I have a long script that is getting stuck while handling the > (enable) mode.
I am trying to authenticate in the following two senarios-
1)
username:
password:
Device>
1st scenario- getting stuck at Device>.
2)
Device>
Same for the 2nd scenario stuck at Device>.
use warnings;
use Net::Telnet;
my $Telnet = new Net::Telnet;
my $InHandle = $Telnet->input_log("input.txt");
my $OutHandle = $Telnet->output_log("output.txt");
my $prmpt = '/[\w().-]*[\$#>:.]\s?(?:\(>\))?\s*$/';
$host="172.16.1.1";
$username = "user";
$password = "pass";
$enpwd = "enable";
my $telnet = Net::Telnet->new(
Host => $host,
Input_log => "input.log",
Output_log => "output.log",
Dump_Log => "dump.log",
Timeout => 10);
# provide host address
$telnet->open("$host");
print "\n\n Connecting to $host\n";
# authentication
@out = $telnet->waitfor('/Username: $/i') || next;
$telnet->print($username);
print "@out\n"; # for tshoot only
@out = $telnet->waitfor('/Password: $/i') || next;
$telnet->print($password);
print "@out\n"; # for tshoot only
# if enable, send "enable" and enable-pwd
unless ($telnet->waitfor('/Username: $/i' | '/#/i'))
{
#$telnet->waitfor('/>/');
@out = $telnet->print('enable');
print "@out\n"; # for tshoot only
@out = $telnet->print($enpwd);
print "@out\n"; # for tshoot only
}
print "username, password, & enable mode authentication accepted-\n";
$telnet->close;
Output:
Connecting to 172.16.1.1
1
1
pattern match timed-out at c:\temp\dirB2D.tmp\testing 3.pl line 35
Press any key to continue . . .
Connecting to 172.16.1.2
pattern match timed-out at c:\temp\dirEDA1.tmp\testing 3.pl line 26
Press any key to continue . . .
I get the username and password passes thru in Scenario 1 but gets stuck in enable. Scenario 2 with .1.2 it doesn't like @out = $telnet->waitfor('/Username: $/i').
Please help!
Updated: code