Using Cisco Telnet and invalid commands aborting job

Using Cisco Telnet and invalid commands aborting job

am 04.10.2005 01:46:27 von Jason Madsen

--===============2098882389==
Content-Type: multipart/alternative;
boundary="----=_Part_10281_6578959.1128383187071"

------=_Part_10281_6578959.1128383187071
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello all,
just want to clarify a little. when i run a perl script to gather
information from a group of cisco switches that i maintain and the switch
doesnt respond or the cmd is invalid the script just times out instead of
going to the next IP address/switch in the list to gather information. does
anyone know how to prevent this from aborting? here's more or less the
script that i've been running:
#!perl -w ###(yea, unfortunately i'm running this on a windows
machine...oh well)
use Net::Telnet::Cisco;

open(OUTFILE, ">flr3rslts.doc");
$start =3D localtime;
print OUTFILE "TIME OF REPORT $start\n\n";
open(INFILE, "flr3list.txt") or die "Can't open flr3list: $!";

while () { # assigns each line in turn to $_
print "$_";

$line =3D ;
print "IP ADDRESS $line\n";
print OUTFILE " IP ADDRESS $line\n";
$timeout1 =3D ("30");
$session1 =3D Net::Telnet::Cisco->new(Host =3D> $line, timeout =3D> "$timeo=
ut1");

###########Login, enable, and run cmd

$session1->login('username', 'password') or die "Unable to login: $!";

if ($session1->enable('password') ) {
my @output =3D $session1->cmd('a cisco cmd such as show mod');

print OUTFILE "@output \n\n";
print @output;

} else {
warn "Can't enable: " . $session1->errmsg;

}

$session1->close;

}

close INFILE;
close OUTFILE;
The flr3list.txt INFILE is just a list of IP addresses that the script uses
to telnet in to my Cisco switches. This script, although I'm sure is full o=
f
at least minor errors, seems to work great for the most part. The one major
downfall is that when a particular cisco switch is down or doesn't support
the cmd I'm running (ie. 'sho mod' is only a valid cmd on modular switches)
the script gets "stuck" for a moment and then closes instead of trying the
next switch/IP on the list. Thanks for any advice you may have.
Jason

------=_Part_10281_6578959.1128383187071
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello all, 

just want to clarify a little.  when i run a perl script to gathe=
r information from a group of cisco switches that i maintain and the switch=
doesnt respond or the cmd is invalid the script just times out instead of =
going to the next IP address/switch in the list to gather information. =
; does anyone know how to prevent this from aborting?  here's more or =
less the script that i've been running:

 


#!perl -w         ###(yea, unf=
ortunately i'm running this on a windows machine...oh well)
use Net::Tel=
net::Cisco;


   open(OUTFILE, ">flr3rslts.doc");
&nb=
sp;  $start =3D localtime;
   print OUTFILE "TIME OF=
REPORT $start\n\n"; 

  open(INFILE,  "flr3list.txt")   or die=
"Can't open flr3list: $!";
   
  whil=
e (<INFILE>) {     # assigns each line in turn to=
$_
          print "=
$_";
 
   $line =3D <INFILE>;=20

   print "IP ADDRESS $line\n";
   prin=
t OUTFILE " IP ADDRESS $line\n";
   $timeout1 =3D (&=
quot;30");
   $session1 =3D Net::Telnet::Cisco->new(Ho=
st =3D> $line, timeout =3D> "$timeout1");=20

###########Login, enable, and run cmd


  $session1->login('username', 'password') or die "Unable t=
o login:  $!";
  


if ($session1->enable('password') ) {
     my =
@output =3D $session1->cmd('a cisco cmd such as show mod');


 print OUTFILE "@output \n\n";
    prin=
t @output;
 
  } else {
      w=
arn "Can't enable: " . $session1->errmsg;


   }
 
 $session1->close;


    }


  close INFILE;
  close OUTFILE; 


The flr3list.txt INFILE is just a list of IP addresses that the s=
cript uses to telnet in to my Cisco switches.  This script, although I=
'm sure is full of at least minor errors, seems to work great for the most =
part.  The one major downfall is that when a particular cisco switch i=
s down or doesn't support the cmd I'm running (ie. 'sho mod' is only a vali=
d cmd on modular switches) the script gets "stuck" for a moment a=
nd then closes instead of trying the next switch/IP on the list.  Than=
ks for any advice you may have.

Jason 


------=_Part_10281_6578959.1128383187071--

--===============2098882389==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============2098882389==--

Re: Using Cisco Telnet and invalid commands aborting job

am 04.10.2005 05:14:08 von Helphand

On Monday 03 October 2005 4:46 pm, Jason Madsen wrote:
> The flr3list.txt INFILE is just a list of IP addresses that the script uses
> to telnet in to my Cisco switches. This script, although I'm sure is full
> of at least minor errors, seems to work great for the most part. The one
> major downfall is that when a particular cisco switch is down or doesn't
> support the cmd I'm running (ie. 'sho mod' is only a valid cmd on modular
> switches) the script gets "stuck" for a moment and then closes instead of
> trying the next switch/IP on the list. Thanks for any advice you may have.

Wrap the section of your code that does the telnet session in
an eval, that way you can test that the session failed, yet continue
on with the next ip number in the file.

Scott

--
POPFile, the OpenSource EMail Classifier http://popfile.sourceforge.net/
Linux 2.6.11.4-21.9-default x86_64
SuSE Linux 9.3 (x86-64)
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs