Solved

ProCurve Switch Backup Script

Posted on 2014-04-28
4
1,049 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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