rtrcommander: Using scripts to push out configurations or retrieve output


rtrcommander is a script I wrote to push out configurations to multiple routers, as well as to retrieve output from the cli. It’s a part of Mr Audit (the release of Mr Audit is delayed while I prepare for the CCIE lab).

rtrcommander can be downloaded here: http://www.synacknetworks.com/scripts/rtrcommander.txt



rtrcommander can be used as follows:

pts/4 jrowley@toolbox:/home/audit/scripts/rtrcmd $> rtrcommander

New and Improved Router Commander 2.0

        Usage:
        ./rtrcommander [-h] -u <username> [-p <password>] -r <rtrlist> -c <cmdlist> [-l <loglocation>]

        -h                : prints this message
        -u                : username
        -p                : password - if not specified, will be prompted
        -r                : file containing list of routers
        -c                : file containing commands to run
        -l                : file where we should log to; defaults to "ipaddress.log"

        Examples:
        rtrcmd -u username -p password -r routerlist -c commandlist
        rtrcmd -u username -r routerlist -c commandlist -l mycombinedlogfile.txt

For security, if a password is not specified on the command line, you will be prompted for one.

This shows how we retrieved memory being held by the Logger process while checking to see our wide spread our memory leak was (see yesterday’s post).

pts/4 jrowley@toolbox:/home/audit/scripts/rtrcmd $> ./rtrcommander -u jrowley -r routers -c commands -l mylog.txt
password: ********

HOSTNAME: router1
Sending: show conf | i ^hostname
Sending: show proc mem sort | i Holding|Logger|Malloc

HOSTNAME: router2
Sending: show conf | i ^hostname
Sending: show proc mem sort | i Holding|Logger|Malloc

HOSTNAME: router3
Sending: show conf | i ^hostname
Sending: show proc mem sort | i Holding|Logger|Malloc

We create two files. One is a list of IP addresses or hostnames of routers we want to run these commands on. The second is a list of commands to run.

routers file:

router1
router2
router3

command file:

show conf | i ^hostname
show proc mem sort | i Holding|Logger|Malloc

If you want to push out some configuration, your command file may look similar to:

config t
ip access-list standard 1
permit 10.20.114.0 0.0.1.255
permit 10.20.164.0 0.0.3.255
end
quit

The combined log file is optional. If you leave it off, it will log everything into one file per router. If you have a small set of routers, you can use either way. Since I typically run stuff against our 600+ routers, I typically combine everything into one log file, otherwise my home directory gets pretty cluttered.

Our combined log file looks like:

pts/4 jrowley@toolbox:/home/audit/scripts/rtrcmd $> more mylog.txt
hostname router1
 PID TTY  Allocated      Freed    Holding    Getbufs    Retbufs Process
  44   0   15619876     170496    8664528      50760          0 Logger
   0   0          0          0    7257808          0          0 *MallocLite*
hostname router2
 PID TTY  Allocated      Freed    Holding    Getbufs    Retbufs Process
  44   0  393743528        188  180671388      71064          0 Logger
   0   0          0          0  139126148          0          0 *MallocLite*
hostname router3
 PID TTY  Allocated      Freed    Holding    Getbufs    Retbufs Process
   0   0          0          0     393528          0          0 *MallocLite*
  44   0   10641592   10607792      30148      10152          0 Logger
pts/4 audit@toolbox:/home/audit/scripts/rtrcmd $>

Non combined logging provides just a bit more details since we use raw Net::Telnet logging

pts/4 jrowley@toolbox:/home/jrowley $> more rtrcmds/2009-11-06/router.log

router line 2

User Access Verification

Username: jrowley
Password:

router#term len 0
router#config t
Enter configuration commands, one per line.  End with CNTL/Z.
router(config)#ip access-list extended OSPF_ROUTES_VOICE
router(config-ext-nacl)#permit ip 10.20.114.0 0.0.1.255 any
router(config-ext-nacl)#permit ip 10.20.164.0 0.0.3.255 any
router(config-ext-nacl)#end
router#quit

This is useful for pushing out the same configuration changes to many routers, or to run commands to capture output, such has how much memory the Logging process is holding.

Hopefully this will be of use for others.

, , ,

  1. #1 by Colby on January 15, 2010 - 9:16 am

    Is rtrcmd yours too? I’ve had it for awhile, but can’t remember where I got it. Looks very similar though.

    Can you modify this to work with SSH (or tell me how)?

    • #2 by jrowley on January 15, 2010 - 10:12 am

      The original rtrcmd isn’t mine (I think Curran wrote the original). I rewrote it and added the combined logging. The original had the rtrcmd.log in your home directory, but when I used it, it only contained the output for one router :)

    • #3 by jrowley on January 15, 2010 - 10:35 am

      Oops. Forgot about your SSH question.

      I’m working on adding that to the pingcheck, backup, and rtrcommander scripts with Net::SSH::Perl.

      Fraizer had written a script that used Net::Appliance::Session, but that module looks a little clunky.

  2. #4 by Colby on January 15, 2010 - 12:48 pm

    Score! Post that ish when you finish it.

(will not be published)