RunRouterCommand.py is a Python application that executes specified commands on a Cisco router.
Exscript module https://github.com/knipknap/exscript/
- This application is hard-coded to use the SSH2 protocol; If SSH v2 is not
enabled on your router(s), you will need to:
- Add
ip ssh version 2
to your Cisco router(s) configuration and any associated access-list changes. or - Alter the
default_protocol
variable in theget_hosts_from_file
function to use a different protocol enabled on your router(s).
- Add
- A valid username/password.
- This application was written for use on Cisco IOS devices and cannot be guaranteed to work on other makes/model routers.
- This application assumes that you have enable privileges on each router in order to execute privileged command. If you do not have sufficient user privileges, this application will not work as designed.
- This application uses the same username/password to access ALL routers. If
your routers use unique usernames/passwords, then this script will not work.
If a password is stored in the
settings.cfg
file, it must be Base64 encoded. - A correctly-formatted config file (default filename is
settings.cfg
). - A correctly-formatted router file (default filename is
routers.txt
). - A correctly-formatted command file (default filename is
commands.txt
).
- Upon execution, the application will search it's local directory for a
config file,
settings.txt
, if one was not provided through the command line during executionpython DownloadRouterConfig.py --config CONFIGFILE
. If a config file was not found or specified, a sample one will be created and the application will exit (END). Edit this file to your specifications before launching the application again. - Upon execution, the application will search for the routerFile variable
specified in the config file (default filename is
routers.txt
). If that file cannot be found, a sample one will be created and the application will exit (END). Edit this file to your specifications before launching the application again. - Upon execution, the application will search for the commandFile variable
specified in the config file (default filename is
commands.txt
). If that file cannot be found, a sample one will be created and the application will exit (END). Edit this file to your specifications before launching the application again. - The application will open an SSH v2 connection to each router in the
routers.txt
file. If the user specified their login credentials in the config file, they will be used. Otherwise, the application will prompt the user to provide their login credentials upon execution. - The application will pass a
terminal length 0
command to the router to avoid any page breaks which will interrupt router output. (It has been my experience in testing that theautoinit()
function provided by Exscript fails to detect Cisco IOS on some routers in our environment.) - The application will read the contents of the
commands.txt
file line by line and pass them to the router as if they were being entered directly at terminal. Be advised that if the router requires extra time to process a command or you attempt to pass too large a command list to the router, it may overwhelm the copy-paste buffer and the router may not successfully execute some commands. - The application will write the the results of the commands as if you were
seeing the output in the terminal. These results will be written to
a file using the format,
HOSTNAME_Results_YYYYMMDD.txt
, where HOSTNAME is the hostname (or IP address) specified in therouters.txt
file and YYYYMMDD is the numerical Year-Month-Day of the box executing the application. These files will be stored in the directory specified by thebackupDirectory
variable in thesettings.cfg
file, or the parent directory of the application if no value was specified. If this file already exists, the filename will be appended with an integer that will continue to increment until the application finds a filename that does not currently exist in that directory. - The application will write a
RunRouterCommand_YYYYMMDD.log
file that identifies the connectivity results from each router. This file will be stored in the directory specified by thelogFileDirectory
variable in thesettings.cfg
file, or the parent directory of the application if no value was specified. If this file already exists, the filename will be appended with an integer that will continue to increment until the application finds a filename that does not currently exist in that directory.