View Single Post
  #1  
Old 02-05-2016, 03:13 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 998
Example: Cisco Save Config to File

Updated 05 Jun, 2020

Ever wanted to quickly save a copy of your Cisco router's running-config or startup-config to a file on your local machine so that you could have something to compare against or restore to? If so, this script is an example you can start with.

Comments within the script file itself provide explanation of how to set it up and what to expect, but if you're looking for a quick way to get started with this example:
  1. Save the script to your local file system.

  2. Map buttons using SecureCRT's button bar to run the script in two different ways.
    1. Map a new button in SecureCRT's button bar with function set to Run Script, pointing to this script.
      Specify "running" as the argument to save a running-config

      Here's another example showing additional arguments passed to the script:


    2. Map another button in the same way.
      Specify "startup" as the argument to save a startup-config


On Windows, when you press the button you've mapped and the script completes, the saved file will be selected in a Windows Explorer file view.
For example:


Note: The example is written in Python code so as to be able to run in SecureCRT on Windows, Linux, or Mac OS X platforms.

Note: The same script will save either the running-config or the startup-config, depending on argument you supply when configuring the script to be launched.

Note: The default behavior is to store resulting config files in your "Documents" folder, in a sub-folder named "Config-Saves".

Options Supported:
  • /auto-close-app:true|false
    If specified as an additional script argument with a value of true, the SecureCRT application will be closed automatically when the script terminates.
    Default: The script does not close SecureCRT automatically when the script is running interactively. When the script is running unattended (not running interactively), the script closes SecureCRT automatically.

  • /confirm-filename:true|false
    If specified as an additional script argument with a value of false, then (when the script is running interactively), the end user is not prompted to confirm the file name when saving the specified config to the local file system. This option has no meaning when /interactive:true is present as an argument.
    Default: The script prompts for file name when running interactively. When running unattended (not running interactively), there is no prompt for filename.

  • /interactive:true|false
    If specified as an additional script argument with value of false, the script runs in unattended mode; no user prompts will appear.
    Default: The script runs in interactive mode by default.

Examples Uses of Arguments:
Save the startup-config to a file, prompting for filename using default template values. SecureCRT continues running after the script completes.
startup

Save the running-config to a file, prompting for filename using default template values. SecureCRT continues running after the script completes.
running

Save the running configuration for just Vlan 1; run unattended, but leave SecureCRT running when the script terminates:
running int Vlan 1 /interactive:true /auto-close:false

Save the more verbose version of a running config (running all); run interactively, but don't prompt for file name to save:
running all /interactive:true /confirm-filename:false

Save the startup-config to a file, but don't prompt for filename -- just save it to the templated name the script provides. SecureCRT continues running after the script completes:
startup /confirm-filename:false

Save the running config; runs unattended and SecureCRT closes automatically when the script completes:
running /interactive:false

--Jake



History:
Update (jdev: 05 Jun, 2020): Merged two example scripts into a single script. This updated version supports Nexus/Catalyst devices, and provides for unattended operation as well as other options as documented above. Note: the Unattended version is no longer being updated.
Update (jdev: 14 Sep, 2017): Added variant of the example script to be useful for unattended backups. See example "Cisco-SaveDeviceConfigToFile-Unattended(NoLongerReceivingUpdates).py.txt"
Update (jdev: 06 Apr, 2018): Updated script to allow for additional argument(s) to 'sh run' to be specified in the button bar configuration. Note: These changes were not made to the 'Unattended' script example.
Update (jdev: 27 Jun, 2017): Use 'more system:running-config' form of the command instead of 'show running-config' for ASA devices so that the resulting output isn't masked (thanks to mike1572 in forum thread 12738 for the tip.).
Update (jdev: 07 Sep, 2016): Updated script to account for other shell/environment differences on ASA devices (use 'term pager 0', and other minor mods). Script now verified working on a Cisco 881W, a 2900 router, a 2960 switch, and an ASA5510 (thanks to forum user mike1572 for assistance).
Update (jdev: 29 Aug, 2016): Updated script to account for shell prompts from ASA devices that have trailing spaces; also account for 'sh term' output that might be longer than one page of data (handle the --more-- prompts if they occur in this scenario).
Update (jdev: 11 Apr, 2016):Updated script to allow/detect hostnames that have digits and dots in them.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support

Last edited by jdev; 06-05-2020 at 05:33 PM. Reason: Updated example to allow for additional arguments (sh run all)