VanDyke Software

Scripting Examples

Index

Cisco Save Running/Startup Config to Local File

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, you can start with this example script: Cisco-SaveDeviceConfigToFile.py.txt.

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 we've provided this example below:

  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:

Notes:

  • The example is written in Python code so as to be able to run in SecureCRT on Windows, Linux, or macOS platforms.
  • 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.
  • The default behavior is to store resulting config files in your "Documents" folder, in a sub-folder named "Config-Saves".

Options Supported:

  • /asa-uses-more:true|false
    If present and set to true, the more:system:running-config command is used instead of show running-config.
    Default: False. The script uses the show running-config command by default if the main argument is "running".
  • /auto-close-app:true|false
    If present and set to true, the SecureCRT application will be closed automatically when the script terminates.
    Default: True if script is running unattended (in other words, the script is not running interactively).
    False by default if the script is running interactively.
  • /confirm-filename:true|false
    If present and set to 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: True, when script is running interactively. False or ignored otherwise.
  • /interactive:true|false
    If present and set to false, the script runs in unattended mode; no user prompts will appear.
    Default: True. The script runs in interactive mode by default.
  • /use-sessmgr-tree:true|false
    If present and set to false, resulting config files are saved in a single, flat destination folder regardless of where the connected session lives within the Session Manager tree.
    Default: True. Resulting config files are stored in a folder structure modeled after the Session Manager folder hierarchy.

Example 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

Save the running config using the more:system:running-config command; runs unattended but does not close SecureCRT automatically when the script completes:

running /interactive:false /asa-uses-more:true /auto-close-app:false

Save complete (including default values) running config (running all). Runs "interactively" but does not prompt for filename (uses default template-based time stamped file name).

running all /interactive:yes /confirm-filename:no /auto-close-app:no /asa-uses-more:no

Same as above, but resulting config files are all stored in the same flat destination folder.

running all /interactive:yes /confirm-filename:no /auto-close-app:no /use-sessmgr-tree:false /asa-uses-more:no

Save the startup config with line numbered mode activated. Interactive (so that, on Windows, the File Explorer will open with the resulting file selected), but automated file name used. Session Manager folder structure is used for determining a mirrored folder in which to store saved config files.

startup linenum /interactive:yes /confirm-filename:no /auto-close-app:no

Same as above, but with a flat folder housing all saved configs rather than mirroring the Session Manager tree.

startup linenum /interactive:yes /confirm-filename:no /auto-close-app:no /use-sessmgr-tree:false

Example Script

Cisco-SaveDeviceConfigToFile.py.txt (33.87 KB)

VanDyke Software uses cookies to give you the best online experience. Before continuing to use this site, please confirm that you agree to our use of cookies. Please see our Cookie Usage for details.