RE: SecureCRT script to backup running configuration through a

From: Huizinga, Rene (rhuizinga@upcbroadband.com)
Date: Tue Sep 25 2007 - 12:13:32 ART


Hi Peter, All,

To give you a method I personally used on my lab-boxes quite a while
ago, which you can maybe copy to this one in a way if willing to go for
an in-band management-solution...

Using physical routers and having enough async-lines on a few Cisco
terminal-servers, I hooked up the aux-ports of all devices to
async-serials on there and ran slip over them. This gave me the addition
of an 'in-band out-of-band' interface :) So on all boxes I configured
this in a separate IP-block, exotic to prevent overlaps where possible
as well as an snmp-server (RW) on there. Then took a linux-box with
UCD-snmp and a few small homebrew scripts to retrieve configs per snmp,
push configs and perform box-reloads. On the TFTP-server I had a small
filesystem-layout individual for each scenario et voila.

The drawbacks were some hassle partially in the labs around the extra
config et all as you can imagine, further the initial setup/development
took some time before all was done and not to forget the fact that in
some cases the slip-setup wasn't 100% stable, but once all was halfway
done it really was nice to play with ! :) Never finished the script 100%
as wanted (before discontinuing playing with the setup), you always come
up with new ideas and other stuff you want to add and the whole thing
can take quite some time depending on the amount of nodes, but OK, in
the end I did have the feeling it was worth it :)

Now maybe here one could think of something like creating a separate
ethernet on each box which you connect to a linux-box or same host even
? With a bit of creativity, some scripting-knowledge and knowing your
own setup one can come a long way....

Cya

-----Original Message-----
From: nobody@groupstudy.com [mailto:nobody@groupstudy.com] On Behalf Of
Peter Kingston
Sent: Tuesday, September 25, 2007 3:39 PM
To: ccielab@groupstudy.com
Subject: SecureCRT script to backup running configuration through a
terminal server

Hello,

I thought i would put this on for the group to see if anyone can help me
with this vbs script or maybe come up with another method.

I use dynamips allot for my studies and stop half way through labs. I
shutdown my server to save power and when I bring it back up, I want a
quick way to put all the configurations back in the routers.

I tried using dynagen's export and import method for a while but it is
to unreliable.

I am trying to get a way to log into the console port of every router
and switch, gather its running configuration and save them to separate
files labeled by the device name.

I currently have the follow script which gathers all the configurations
but puts them all in the one file output.txt: (it is probably a very
ugly script, but it works)

# $language = "VBScript"
# $interface = "1.0"

'=======================================================================
===
' NAME: Cisco Backup Configuration
' AUTHOR: Peter Kingston
' DATE : 09/25/2007
'=======================================================================
===

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Sub Main
    Const DEVICE_FILE_PATH = "C:\Documents and Settings\c818935\My
Documents\SecureCRT\ChangeRouterPasswords\devices2.txt"

    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim fil
    Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

    Dim file
    Set file = fso.OpenTextFile("c:\temp\output.txt", ForWriting, True)

    Dim ip
    Dim name
    Dim port
    Dim protocol
    Dim line
    Dim cnxnString
    While Not fil.AtEndOfStream
        line = fil.ReadLine

        name = Split(line, ";")(0)
        ip = Split(line, ";")(1)
        port = Split(line, ";")(2)
        protocol = Split(line, ";")(3)

        Select Case protocol
            Case "Telnet"
                cnxnString = "/TELNET " & ip & port
        End Select

        ' Connect
        crt.Screen.Synchronous = True
        crt.Session.Connect cnxnString
        crt.Screen.Send VbCr & VbCr & VbCr & VbCr & VbCr & VbCr

        ' Enable
          crt.Screen.Send "en" & vbCr
          crt.Screen.Send "term length 0" & vbCr
          crt.Screen.Send "show run" & vbCr & Chr(10) & "show ver" &
vbCr
          crt.Screen.WaitForString Chr(10)

        ' Create an array of strings to wait for.
          '
          Dim waitStrs
          waitStrs = Array( Chr(10), "IOS" )

          Dim row, screenrow, readline, items
          row = 1

          Do
            While True

              ' Wait for the linefeed at the end of each line, or the
shell prompt
              ' that indicates we're done.
      '
      result = crt.Screen.WaitForStrings( waitStrs )

      ' If we saw the prompt, we're done.
      If result = 2 Then
        Exit Do
      End If

      ' The result was 1 (we got a linefeed, indicating that we received
      ' another line of of output). Fetch current row number of the
      ' cursor and read the first 80 characters from the screen on that
row.

      '
      ' This shows how the 'Get' function can be used to read
line-oriented
      ' output from a command, Subtract 1 from the currentRow to since
the
      ' linefeed moved currentRow down by one.
      '
      screenrow = crt.screen.CurrentRow - 1
      readline = crt.Screen.Get(screenrow, 1, screenrow, 80 )

      ' NOTE: We read 80 characters from the screen 'readline' may
contain
      ' trailing whitespace if the data was less than 80 characters
wide.

      ' Write the line out with an appended '\r\n'
      file.Write readline & vbCrLf
    Wend
  Loop

        crt.Screen.Synchronous = False
        crt.Session.Disconnect
    Wend

    fil.Close
End Sub

------------------------------------------------------------------------
----------------------
the following is the output from devices2.txt

Rack1R1;192.168.0.12; 2001;Telnet
Rack1R2;192.168.0.12; 2002;Telnet
Rack1R3;192.168.0.12; 2003;Telnet
Rack1R4;192.168.0.12; 2004;Telnet
Rack1R5;192.168.0.12; 2005;Telnet
Rack1R6;192.168.0.12; 2006;Telnet
Rack1SW1;192.168.0.12; 2007;Telnet
Rack1SW2;192.168.0.12; 2008;Telnet
Rack1SW3;192.168.0.12; 2009;Telnet
Rack1SW4;192.168.0.12; 2010;Telnet

------------------------------------------------------------------------
----------------------

The above method is very quick to gather the configurations but it isn't
very quick to put them back on the devices.

I know this is sort of off topic but this script might also help someone
else here.

Your welcome to use it.

--
Regards,

Peter Kingston Studying my CCIE



This archive was generated by hypermail 2.1.4 : Sat Oct 06 2007 - 12:01:15 ART