http://qs321.pair.com?node_id=1029009


in reply to Re: Telnet Cisco routers
in thread Telnet Cisco routers

Hi i was trying the suggestion you gave me and i have some problems or nubs questions ... here is what i have

use Net::Telnet::Cisco; for ($i = 4; $i <= 10; $i++){ $device = "172.16.$i.251"; my $pe = $i; my %users = ("6" =>"none", ); my %pwds = ("6" =>"thispass", ); my $curpwd = "admin"; if (defined $pwds{$i}) { $curpwd = $pwds{$i}; } if ($users{$i} eq "none") { $session->login(Password => $curpwd); } else { $session->login(Name => 'admin', Password => $curpwd, Input_log => " +perllogrouter/router$i.log",); } $session->cmd ("sh running-config | redirect ftp://172.25.1.101/proba +$pe.txt"); $session->close; }

and this is the error i get when i try to run this

C:\Users\mydesktop\Desktop\Perl>perl telnet.pl

Name "main::device" used only once: possible typo at telnet.pl line 5.

Use of uninitialized value within %users in string eq at telnet.pl line 16.

Can't call method "login" on an undefined value at telnet.pl line 19.

C:\Users\mydesktop\Desktop\Perl>

Any suggestion about this because im still learning the perl and some of the errors that i get im not quite sure what are telling me

Replies are listed 'Best First'.
Re^3: Telnet Cisco routers
by Illuminatus (Curate) on Apr 18, 2013 at 15:34 UTC
    You have violated the first commandment, "Thou shalt not write programs without 'use strict' and 'use warnings'". Your declaration of $device likely conflicts with a global in the telnet package.

    fnord

      UFF :S sorry for that my mistake. Any way i use it but as noob i cant figuring still what im doing wrong ... for now im not in the work ( medical issue ) and i cant test it ... im trying now at home with some improvisation and here is what i got using this code

      use Net::Telnet::Cisco; use strict; use warnings; use diagnostics; my %users = ("6" =>"none", ); my %pwds = ("6" =>"thispass", ); my $i = 4; for ($i; $i <= 10; $i++){ my $device = "10.10.$i.1"; my $pe = $i; my $curpwd = "admin"; if (defined $pwds{$i}) { $curpwd = $pwds{$i}; } if ($users{$i} eq "none") { my $session->login(Password => $curpwd); } else { my $session->login(Name => 'admin', Password => $curpwd, Input_log + => "perllogrouter/router$i.log",); } $session->cmd ("sh running-config | redirect ftp://192.168.1.10/pr +oba$pe.txt"); $session->close; }
      and here is what i get from that ..
      C:\Users\mydesktop\Desktop\Perl>perl telnet2.pl Global symbol "$session" requires explicit package name at telnet2.pl +line 24. Global symbol "$session" requires explicit package name at telnet2.pl +line 25. Execution of telnet2.pl aborted due to compilation errors.
      After i put "my" in session at line 24 and 25 i get this
      C:\Users\mydesktop\Desktop\Perl>perl telnet2.pl "my" variable $session masks earlier declaration in same scope at teln +et2.pl line 25. Useless use of private variable in void context at telnet2.pl line 26. Use of uninitialized value within %users in string eq at telnet2.pl li +ne 19. Can't call method "login" on an undefined value at telnet2.pl line 22. C:\Users\mydesktop\Desktop\Perl>
      So pls can you suggest what im doing wrong ... im now im noob and this is easy but the time is not on my side this few weeks. Im trying to read this book but im still at Strict,Warnings,and Diagnostics Chapter3 Variables :) and yes we all understand variables but i just fall in love with perl and i dont like to skip any chapter or something :) love is come again :) .... tnx in advanced for the support and any help you gave me .....