Re: Anyone doing this?

From: Dan.Thorson@seagate.com
Date: Sun Feb 22 2004 - 00:39:09 GMT-3


I do stuff like this for TAC all the time... using PERL scripts and the
Net::Telnet::Cisco modules. SUPER easy to do, and really comes in handy
later....

Call this script as follows
      ./scriptname RouterName TelnetPwd EnaPwd OutputFilename

Just change/add/delete the calls to "docmd" at the end of the script to
customize for your purposes.

danT

=========================================================
#!/usr/local/bin/perl

$dbg=1;

use Net::Telnet::Cisco ();

$host=$ARGV[0];
$password=$ARGV[1];
$enapass=$ARGV[2];
$outfile=$ARGV[3];

print "host is $host\n" if $dbg;
print "pass is $password\n" if $dbg;
print "ena is $enapass\n" if $dbg;
print "file is $outfile\n" if $dbg;

$secs = 5 * 60;
$MB = 1024 * 1024;

sub docmd {
   ($cmd) = @_;
   print "Doing command $cmd\n" if $dbg;
   @output = $session->cmd( String => $cmd, Timeout => $secs);
   print FILE "\n\n";
   print FILE "========= ========= ========= ========= =========
=========\n";
   print FILE "========= RESULTS OF \"$cmd\"\n";
   print FILE "========= ========= ========= ========= =========
=========\n";
   print FILE @output;
}

print "\n\nOpening output file $outfile\n" if $dbg;
open(FILE,">$outfile") || die ("Couldn't open $outfile");
print "done\n" if $dbg;

print FILE "Connecting to $host\n";
print "Connecting to $host...\n" if $dbg;
$session = new Net::Telnet::Cisco (Host => "$host");
$session->max_buffer_length(5 * $MB);
$session->login('',$password);

print "... setting enable\n";
if ($session->enable($enapass) ) {
   @output = $session->cmd('show privilege');
   print FILE "My privileges: @output\n";
} else {
   warn "Can't enable: " . $session->errmsg;
}

docmd("term len 0");
docmd("show version");

$session->close;

===================================================
Dan Thorson - Seagate Technology - CCIE 10754
desk +1 (952) 402-8293 fax +1 (952) 402-1007
SeaTel 8-402-8293
===================================================



This archive was generated by hypermail 2.1.4 : Fri Mar 05 2004 - 07:13:54 GMT-3