From: Peter Kingston (kingstonp.ccie@gmail.com)
Date: Tue Sep 25 2007 - 10:39:17 ART
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