coldroom has asked for the wisdom of the Perl Monks concerning the following question:

Hello There,

Before, sorry for my english.

Well, what I want : Doing a script which do a config backup of a looong nortel (Baystack) switch's list.

My problem, it seem I can't log on them correctly !

Manually, I have to connect, press Ctrl-Y, enter my login, my password, press Shift+C to enter in the command line and do what i want.

Actually, my script works ONLY if i don't have to login on my switch. When I have to logon, I don't have error message, but the config file server tftp side is emtpy..

Note that I can't use SNMP method or Expect.

Here's the code :

#!/usr/bin/perl use Net::Telnet; $serveur_tftp = 'x.x.x.x'; our $switchlist_nortel_conf = "nortel.txt"; our @devices_nortel; open(FILEHANDLER, "<$switchlist_nortel_conf") or die "ERREUR : $switch +list_nortel_conf n'existe pas !\n"; while (<FILEHANDLER>) { next if (/^\n$/); next if (/^#/); chomp; push (@devices_nortel, $_); } close(FILEHANDLER); foreach $switch_nortel_conf (@devices_nortel) { &Recup_nortel; } sub Recup_nortel { @switch_nortel_details = split(/ /, $switch_nortel_conf); $prompt = qw(/\>/); $out_log='log/Out_Log_'.@switch_nortel_details[1].'.txt'; $in_log='log/In_Log_'.@switch_nortel_details[1].'.txt'; $dump_log='log/Dump_Log_'.@switch_nortel_details[1].'.txt'; $t= new Net::Telnet (Timeout=>55, Errmode=>'return', Dump_log=>$dump_log, Input_log=>$in_log, Output_log=>$out_log, prompt=>$prompt ); $t->open(@switch_nortel_details[0]) or die $t->errmsg;; print ("DEBUG : Connexion effectuée\n"); print ("DEBUG : Envoi de Ctrl-Y \n"); $var_0=chr(25); @ctrly=$t->print($var_0) or die $t->errmsg; print ("DEBUG : Envoi du login => @switch_nortel_details[3]\n"); $t->waitfor('/Username:/i'); $var_1="@switch_nortel_details[3]"; @login=$t->print($var_1) or die $t->errmsg; print ("DEBUG : Envoi du password => @switch_nortel_details[2]\n") +; $t->waitfor('/Password:/i'); $var_2="@switch_nortel_details[2]"; @password=$t->print($var_2) or die $t->errmsg; print ("DEBUG : Selection de la ligne de commande (envoi de Maj+C) + \n"); $var_3=chr(67); @majc=$t->print($var_3) or die $t->errmsg; print ("DEBUG : Envoi de enable\n"); $t->cmd("enable") or die $t->errmsg; print ("DEBUG : Envoi de copy running-config tftp address $serveur +_tftp filename @switch_nortel_details[1]\n"); $t->cmd("copy running-config tftp address $serveur_tftp filename @ +switch_nortel_details[1]"); #or die $t->errmsg; print ("DEBUG : Envoi de close\n"); $t->close or die $t->errmsg; return 1; } exit;

Note : If I #comment all the identification lines, and I try to connect on a unsecured switch, all works fine !

Please help, I am on this problem since a big week :\

Many Thanks

Ju update :

the in_log :

Ethernet Switch 470-24T HW:07 FW:3.6.0.7 SW:v3.7.0.04 ISV +N:2 Username: [ ] [ *************** ] Enter Username: julian@tri-srv-jh:~/telnet$ Enter text, press <Return> or <Enter> when complete.

the outlog :

julian@tri-srv-jh:~/telnet$ cat log/Out_Log_470_BS9.txt mylogin mypassword C enable copy running-config tftp address x.x.x.x filename 470_BS9

And the prompt clientside :

DEBUG : Connexion effectuée DEBUG : Envoi de Ctrl-Y DEBUG : Envoi du login => mylogin DEBUG : Envoi du password => mypassword DEBUG : Selection de la ligne de commande (envoi de Maj+C) DEBUG : Envoi de enable DEBUG : Envoi de copy running-config tftp address x.x.x.x filename 470 +_BS9 DEBUG : Envoi de close

Replies are listed 'Best First'.
Re: Noway to login correctly into Nortel Switch
by roboticus (Chancellor) on Jan 21, 2010 at 11:24 UTC

    coldroom:

    How far into the login process are you getting? I can't really suggest anything if I don't know what's broken.

    I'd suggest that you run a network analyzer during a manual login and compare it with the traffic you get with your script and find out what the differences are.

    Anyway, a few suggestions:

    • Perhaps you should use put when you write the ^Y. It may be that the newline after the ^Y is preventing the switch from waking up and talking to you.
    • Don't use useless variable names (e.g. $var_0). Either give them a good name like $ctrl_Y or just skip them like so: $retcod=$t->print(chr(25));
    • Read the documentation so you can use the telnet session object correctly, the print method doesn't return what you think it does.
    • Is the line selection character really 'C'? If so, you might want to send 'C' rather than making future maintainers figure it out from chr(67).

    ...roboticus

Re: Noway to login correctly into Nortel Switch
by Anonymous Monk on Jan 21, 2010 at 17:28 UTC

    Should $prompt = qw(/\>/); be $prompt = '/\>/'; which is one of the defaults anyway?

    use warnings; use strict;

    and from the docs;

    With no argument this method returns the prompt set in the object. With an argument it sets the prompt to $matchop and returns the previous value. The default prompt is '/\$%#> $/' Always use single quotes, instead of double quotes, to construct $matchop (e.g. '/bash\$ $/'). If you're constructing a DOS like file path, you'll need to use four backslashes to represent one (e.g. '/c:\\\\users\\\\bill>$/i'). Of course don't forget about regexp metacharacters like ., [, or $. You'll only need a single backslash to quote them. The anchor metacharacters ^ and $ refer to positions in the input buffer.