download routerexec.pl

This script can be used to collect data from cisco/zebra-routers
or to make configurations, or do whatever you do when you type commands
in a router to do the things that make (you|your boss) happy
examples:
fredrik@localhost> routerexec.pl 

Usage: routerexec.pl [-h] [-r] [-n] [-f /path/to/passwordfile] [-u userid] [-p "password"] [-e "enablepassword"] [-o /path/to/outputfile] [-s] [-t ] -c | &|

-h      Print this help

-r      enable, will exec the commands in enable-mode

-f      alternative passwordfile, default is /home/someuser/ciscopasswords-in-a-file
        the format for this file is:
        routername1 userid password enablepassword
        routername2 userid password enablepassword

-u      if you don't want to use a passwordfile you can specify user here.

-p      and a password for this user. Only valid if you do not use a passwordfile.

-e      and the enablepassword. Only valid if you do not use a passwordfile.

-o      save the output to file(s), if filename is ROUTER, the script will save
        the output to unique files in current directory based on the routername. 
        Otherwise the output will be appended to the name specified. If the file
        exist it will contain old and new data.

-c      commands, either e.g "sh ver" or ./file which contains a list of commands,
        if ./file contains the word ROUTER this text will be replaced with the current
        name of the router logged in to. 

-s      use SSH instead of telnet. In ciscos this can only be used to send single
        commands since they only use SSHv1. No configure etc.

-n      do NOT use 'user, password' but just a simple 'password' to login to the
        router, this option accepts a passwordfile in the format:
        router1 password enablepassword
        router2 password enablepassword
        and this does not work with ssh, just with telnet.

-t      use this port instead of the default 23 for telnet. (good for eg zebras)

Examples:

routerexec.pl -c "sh log" routername

routerexec.pl -r -c "sh run" -o ROUTER router1 router2 ./file-with-routernames

routerexec.pl -c ./file-with-commands ./file-with-routernames

routerexec.pl -u myloginid -p "mypassword" "sh ip int br" router1

routerexec.pl -f ./mypasswordfile -o all-output.txt -e -c "sh run | inc nterface|escr" ./file-with-routernames


If I want to make a single command in a single router I can do like this:
routerexec.pl -u userid -p secretpassword -c "sh ver" myroutername

or if I want enable-mode:
routerexec.pl -r -u userid -p secretpassword -e theenablepassword -c "sh run" myroutername

or if I want to do this in many routers:
routerexec.pl -r -u userid -p secretpassword -e theenablepassword -c "sh run" myroutername1 myroutername2 muroutername3 

to make this easier I can put the routernames in a file and point the script to that file instead
routerexec.pl -r -u userid -p secretpassword -e theenablepassword -c "sh run" ./file-with-routernames

and if I'm really lazy, I create a passwordfile with the routernames and passwords, like this:
routername1 userid password enablepassword
routername2 userid passwordx enablepassword
routername3 userid passwordy enablepasswordz
and point my script to that file like this:
routerexec.pl -r -c "sh run" -f ./file-with-passwords ./file-with-routernames
or, suppose I'm even more lazy, I hack the script to point to my default passwordfile
and it works like magic
routerexec.pl -r -c "sh run"  ./file-with-routernames
Ok, suppose I want to run configure-commands, or many commands in a row?
just create a file with the commands, like this:
conf t
no ip as-path access-list 10 
ip as-path access-list 10 permit _(1234|2345|3456)$
ip as-path access-list 10 permit _(4567|5678|6789)$
end
wr
quit
and run the script like:
routerexec.pl -r -c ./file-with-commands  ./file-with-routernames
hmm, I want to save the output in different named files, and I do not
know how to make scripts to do that for me, I will just use this and the
output will be saved to different files named to the routernames:
routerexec.pl -r -c ./file-with-commands  ./file-with-routernames -o ROUTER

Ok, I do not use a cisco, I use zebra, and the zebra runs the telnetdaemons
on another port... well, use this:
routerexec.pl -r -t 2605 -c ./file-with-commands  ./file-with-routernames 

Well, that would be nice if the zebra used tacacs, then use another format
of the passwordfile, like this:
routername1 password enablepassword
routername2 passwordx enablepassword

and use this command:
routerexec.pl -r -n -t 2605 -c ./file-with-commands  ./file-with-routernames