Re: Syslog's

Ron Parker (rparker@gator1.brazosport.cc.tx.us)
Wed, 6 Aug 1997 11:05:56 -0500 (CDT)

I've included a perl script at the end of this message, that someone else
wrote, that I use in a chron job to grab the five minute statistics from a
Cisco router. I just run this every five minutes and direct the output to
a file. It gives me the basic numbers I'm interested in tracking without a
lot of fuss. I'm working on implementing MRTG but this script works for
now.

--
Ron Parker
Network Communications Specialist
Brazosport College

On Sat, 2 Aug 1997, RTS wrote:

> > New to monitoring stats..... > > What is a good tool to use to see how much bandwidth we are using through > our serial 0 T1 connection on our Cisco 2501 router?? > > This connection is our connection to the Internet...back to our provider > for our lan. > > Randy > rts@rdr.net > > RTS > rts@rdr.net > Always Looking For A Better Way > > Oh Yea...Found a better way.... > > RaDaR Computer Solutions (rdr.net) >

*******START Cisco script***************

#!/usr/local/bin/perl # # $Header: /home/netmgt/nocol/src/perlnocol/RCS/rcisco,v 1.3 1993/10/17 11:55:33 aggarwal Exp $ # # rcisco - perl routine to execute a Cisco router command remotely # # Programmer: Christopher Sedore # Revised by: John Wobus, jmwobus@mailbox.syr.edu # # (c) Syracuse University Computing & Network Services 1993 # # No warranty is expressed or implied. Permission to copy and use is # extended to all. Permission to redistribute is granted under the # following conditions: it is not sold for profit; this copyright # notice remains intact; the same permissions extend to the recipient; # and if any changes are made, a notice is added so stating. # # Command Format: # # rcisco <router> <command> [<port>] # # Signs on to Cisco router, executes command, and returns the # result. # # <router> - the name or IP number of the Cisco router. # <command> - the Cisco router command, e.g. "show interfaces". # <port> - the TCP port: 23 by default. # # Example Call: # # rcisco mycisco.excellent.edu "show hardware" # # This command signs on to myscisco.excellent.edu, executes the # command "show hardware" and sends the result to the standard # output. # # Depends upon: # hostname - Unix command to list a host's name. # # To install this: # (1) Assign the perl variables below appropriately. # (2) Put this file whereever you want. #

#

$defaultrouter="123.456.789.012"; # Default router. $defaultpasswd="password"; # PW of the router. $defaultcommand="show int s 1 "; # Command to exec on router $defaultport=23; # Default TCP port.

# # main routine #

($them,$passwd,$command,$port) = @ARGV; $them = $defaultrouter unless $them; $passwd = $defaultpasswd unless $passwd; $command = $defaultcommand unless $command; $port = $defaultport unless $port; # usually should be port 23

$AF_INET = 2; $SOCK_STREAM = 1;

$SIG{'INT'} = 'dokill'; sub dokill { kill 9,$child if $child; }

# require "$socketph";

$sockaddr = 'S n a4 x8'; chop($hostname = `hostname`);

($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); if ($them =~ /^\d+/) # IP address specified { local(@a) = split (/\./,$them); $thataddr = pack ('C4', @a); } else { ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them); }

$thataddr || die "Unknown host: $!";

$this = pack($sockaddr, $AF_INET, 0, $thisaddr); $that = pack($sockaddr, $AF_INET, $port, $thataddr);

socket(S, $AF_INET, $SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; connect(S, $that) || die "connect: $!";

select(S); $| = 1; select(STDOUT); # set socket to be command buffered

if ($child = fork) { print S "$passwd\n"; print S "terminal length 0\n"; # dont need a 'more' sleep 1; #some routers work better with this. # print S "enable\n"; # print S "$passwd\n"; # sleep 1; print S "$command\n"; print S "quit\n"; sleep 3; do dokill(); } else { while (<S>) {print;} }