Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ProCurve Switch Backup Script

Posted on 2014-04-28
4
Medium Priority
?
1,208 Views
Last Modified: 2014-04-28
I am trying to get the following script to work in our environment and the author is unresponsive.
Here is the original article:
http://www.experts-exchange.com/Hardware/Networking_Hardware/Switches/A_10799-Backing-up-Configuration-settings-HP-ProCurve-switches'.html

 I have setup the directory and scripts as follows:
BackupScript.vbs, this contains the meat of the scripting and should work, but when I run it I get an error about a " ' " on line 14 Char 30...
*Note, thie orig article does not say what type of script to save the file as, it may or may not be a visual basic script...

Backups Directory, this is where the SwitchBackup.cfg should end up
Then I have both the tftpd32.exe and its ini file, and the TST10.exe programs for the script to call...
ListSwitch.txt has a list of my switch IP addresses in it for the script to loop through.

here is the code for the BackupScript.vbs, what am i missing here:

CODE:
Set IPTftpHost = "192.168.1.185" 'This is where the TFTP IP is declared. 
Set NameCMDFile = "Runbackup.cmd" 'This is the name of the command file that will be created.


Set fso = CreateObject("Scripting.FileSystemObject") 'Scripting.FileSystemObject declare. 
Set f = fso.OpenTextFile(NameCMDFile, 2, True) 'Creating/opening the command file.
Set listFile = fso.OpenTextFile("ListSwitch.txt") 'This is the list of IP addresses of your switches'
Set shell = CreateObject("WScript.Shell") 'WScript shell declare
shell.Run """.\tftpd32.exe""", 1, false' We start the TFTP server
Do while not listFile.AtEndOfStream 'This is the start of the loop for the file with the list of switches.
	fName =  listFile.ReadLine()'Fname is the line read from the file.
	Set filetxt = fso.CreateTextFile(fName & ".txt", True)'We create a textfile with the IP of the switch
	filetxt.WriteLine("" & _
		fName & " 23" & vbCrLf & _ 'Connection string
		"WAIT ""Username"""& vbCrLf & _'Waiting for Username Prompt
		"SEND ""admin\m"""& vbCrLf & _'Sending 'admin' text string
		"WAIT ""Password"""& vbCrLf & _'Waiting for Continue
		"SEND ""mypassword\m"""& vbCrLf & _'Sending 'admin' text string
		"WAIT ""SW"""& vbCrLf & _'Wait for SW(This is for the switch name)
		'"SEND "" \m"""& vbCrLf & _'Sending nothing(Press any key to continue)
		'"SEND "" \m"""& vbCrLf & _'Sending nothing(Press any key to continue)
		"SEND ""copy run tftp "& IPTftpHost & " " & fName & ".cfg"""& vbCrLf & _'This is the important part, this is where you copy RUN over TFTP to your server
		"WAIT ""SW"""& vbCrLf & _'Wait for SW(This is for the switch name)
		"SEND "" \m"""& vbCrLf & _'Send nothing
		"SEND ""logout\m"""& vbCrLf & _'Send the logout command
		"WAIT ""log out"""& vbCrLf & _'Wait for log out y/n
		"SEND ""y\m"""& vbCrLf & _'Send yes
		"SEND ""n\m"""& vbCrLf & _'Send no(this must be done on some switches)
		"")'We write the telnet commands to the .txt
	filetxt.Close 'We close the filestream.
	f.WriteLine("tst10 /r:" & fName & ".txt /m")'We write the command to the CMD file.
	f.WriteLine("DEL """ & fName & """.txt")'After that we write the delete command to the CMD file.
Loop 'End loop
f.WriteLine("taskkill /IM tftpd32.exe")'We kill the TFTP server
f.WriteLine("MOVE *.cfg .\Backups")'We move all files with .cfg to another location.
f.close'We close the file stream.
shell.Run NameCMDFile, 1, true'We run the CMD file.
fso.deletefile(NameCMDFile)'When it's all done we delete the CMD file.

Open in new window


Thanks for any help...
0
Comment
Question by:speeDemon
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
jburgaard earned 2000 total points
ID: 40027693
AFAIK you can’t use the continuation character (underscore) with comments. Every line that has a comment must start with a single quote.
So I would try remove the comments from continuation lines.
0
 

Expert Comment

by:jdouthit
ID: 40028111
We use a program Solarwinds to backup all of our switches and routers.  It is called CatTools.

http://www.solarwinds.com/kiwi-cattools.aspx
0
 
LVL 1

Author Closing Comment

by:speeDemon
ID: 40028314
Perfect here is the final script:
The ListSwitch.txt file needs to have the Switch IP on one line, then the Switch Name on the next then start over...
Example:
192.168.1.1
Switch1
192.168.1.2
Switch2



<CODE>
IPTftpHost="192.168.1.185" 'This is where the IP is declared.
NameCMDFile = "Runbackup.cmd" 'This is the name of the command file that will be created.


Set fso = CreateObject("Scripting.FileSystemObject") 'Scripting.FileSystemObject declare.
Set f = fso.OpenTextFile(NameCMDFile, 2, True) 'Creating/opening the command file.
Set listFile = fso.OpenTextFile("ListSwitch.txt") 'This is the list of IP addresses of your switches'
Set shell = CreateObject("WScript.Shell") 'WScript shell declare

shell.Run """.\tftpd32.exe""", 1, false' We start the TFTP server
Do while not listFile.AtEndOfStream 'This is the start of the loop for the file with the list of switches.
      fName = listFile.ReadLine()'Fname is the line read from the file.
      fSwitchName = listFile.ReadLine()'Fname is the line read from the file.
      Set filetxt = fso.CreateTextFile(fName & ".txt", True)'We create a textfile with the IP of the switch
      filetxt.WriteLine("" & _
            fName & " 23" & vbCrLf & _
            "WAIT ""Username:"""& vbCrLf & _
            "SEND ""admin\m"""& vbCrLf & _
            "WAIT ""Password"""& vbCrLf & _
            "SEND ""mypassword\m"""& vbCrLf & _
            "SEND "" \m"""& vbCrLf & _
            "WAIT """& fSwitchName &""""& vbCrLf & _
            "SEND ""copy run tftp "& IPTftpHost & " RunningConfig_" & Year(Date) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & "_" & fSwitchName & ".cfg"""& vbCrLf & _
            "WAIT """& fSwitchName &""""& vbCrLf & _
            "SEND "" \m"""& vbCrLf & _
            "SEND ""logout\m"""& vbCrLf & _
            "WAIT ""log out"""& vbCrLf & _
            "SEND ""y\m"""& vbCrLf & _
            "SEND ""n\m"""& vbCrLf & _
            "")
      filetxt.Close 'We close the filestream.
      f.WriteLine("tst10 /r:" & fName & ".txt /m")'We write the command to the CMD file.
      f.WriteLine("DEL """ & fName & """.txt")'After that we write the delete command to the CMD file.
Loop 'End loop
f.WriteLine("taskkill /IM tftpd32.exe")'We kill the TFTP server
f.WriteLine("MOVE *.cfg .\Backups")'We move all files with .cfg to another location.
f.close'We close the file stream.
shell.Run NameCMDFile, 1, true'We run the CMD file.
fso.deletefile(NameCMDFile)'When it's all done we delete the CMD file.
</CODE>

Thanks for the help
0
 
LVL 17

Expert Comment

by:jburgaard
ID: 40028410
Thank YOU
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I eventually solved a perplexing problem setting up telnet for a new switch.  I installed a new Cisco WS-03560X-24P switch connected to an existing Cisco 4506 running a WS-X4013-10GE Sup II-Plus. After configuring vlans and trunking,  I could no…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

578 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