Solved

Automate switch config backup

Posted on 2016-11-28
3
19 Views
Last Modified: 2016-11-29
I have a list of switches that I want to copy the config from.  I have a script that I can copy the config from one of them.  Can you help me modify this for many switches? They are all the same model.  This script connects via telnet and saves the config to a tftp server.

<job>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet 172.25.209.254 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("^Y")
WScript.Sleep 1000
WshShell.SendKeys ("EN")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys ("copy running-config tftp address 172.24.109.124 filename Backup2.txt")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("logout")
WScript.Sleep 1000
WshShell.SendKeys ("{Enter}")
WScript.Quit 
</script>
</job>

Open in new window

0
Comment
Question by:Roccat
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 41905259
all I have done is split the telnet code out into a Sub and then called it using different target and backupfiles
you could also consider a telnet app that lets you supply a command file as sendkeys is often unreliable.

Option Explicit

SaveConfig "172.25.209.254" "172.24.109.24" "backup254.txt"

SaveConfig "172.25.209.252" "172.24.109.24" "backup252.txt"


WScript.Quit

Sub SaveConfig(srcIP, destIP, destFile)
	On Error Resume Next
	Dim WshShell
	set WshShell=CreateObject("WScript.Shell")
	WshShell.run "cmd.exe"
	WScript.Sleep 1000
	'WshShell.SendKeys "telnet 172.25.209.254 23"  '---orig
	WshShell.SendKeys "telnet " & srcIP & " 23"
	WshShell.SendKeys ("{Enter}")
	WScript.Sleep 1000
	WshShell.SendKeys ("^Y")
	WScript.Sleep 1000
	WshShell.SendKeys ("EN")
	WScript.Sleep 1000
	WshShell.SendKeys ("{Enter}")
	WScript.Sleep 3000
	''WshShell.SendKeys ("copy running-config tftp address 172.24.109.124 filename Backup2.txt")   '' ---orig
	WshShell.SendKeys ("copy running-config tftp address " & destIP & " filename " & destFile)
	WScript.Sleep 1000
	WshShell.SendKeys ("{Enter}")
	WScript.Sleep 1000
	WshShell.SendKeys ("logout")
	WScript.Sleep 1000
	WshShell.SendKeys ("{Enter}")
End Sub
 

Open in new window

0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 41905266
0
 

Author Closing Comment

by:Roccat
ID: 41905632
Thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now