Net::Telnet - Problems using "script->waitfor" - HELP Needed
am 26.11.2005 10:13:46 von mark1.thompson45Hello All,
I am having problems getting my Perl script to detect
different login scenarios in a unix environment. My code will work OK
for one box but every now and then a box will be configured differently
and the login prompts will be different, catering for this eventuality
in my script is where I am struggling, here is a snippet of the code:-
------------------------------------------------------------ ------------------------------------------------------------ ---------------
sub Telnet_To_Device
{
$script = new Net::Telnet ( Timeout=>5, Errmode=>'return', Prompt =>
"/:/i");
$script->dump_log(@Data[0]."debug.log");
if (!($script->open(@Data[1])))
{
print "FAILED TO CENNECT TO @Data[1]\n";
return;
} else {
$script->waitfor('/login:/i');
$script->print(@Data[2]);
$script->waitfor('/password:/i');
$script->print(@Data[3]);
$script->waitfor('/Do you understand/i');
$script->print('Y');
$script->waitfor('/:/');
#uname();
$script->print('quit');
}
}
------------------------------------------------------------ ------------------------------------------------------------ ---------------
As I said this will work for 80% of my machines but for the other 20%
there is a sticking point at the point just after where I input the
password, for these 20% of boxes they do not prompt the user for "Do
you understand" and expect the user to return either "Y/N" they go
straight to the box shell prompt. How can I get the code to say if you
see this then do this or if you see that then do that, an 'IF'
statement basically, the only way I can see this working is if you have
a list of the boxes that do this and then you can use an IF on the box
names to present different logins, this seems to long winded though,
there must be an easier route.
p.s. I have read the PM file before anyone asks, I could not find the
answer there.
Cheers, Mark.